summaryrefslogtreecommitdiffstats
path: root/testing/robot
diff options
context:
space:
mode:
authorjuraj.linkes <jlinkes@cisco.com>2017-06-27 16:39:39 +0200
committerjuraj.linkes <jlinkes@cisco.com>2017-06-27 16:39:39 +0200
commit5363f1bd4b2007bc66f4171069251f813ff2b418 (patch)
treee6a31f872cd45a19be784fd8cd4bff1dcfd961f7 /testing/robot
parente52796576836ee2f3b2b36c63503ceb1cf6588f3 (diff)
Updated robot scripts for v3 credentials
The fds security group robot script is now compatible with both v2 and v3 credentials. Also introduced other minor fixes. Change-Id: I987a3963fea425fcc31afe4681575ca985f162bb Signed-off-by: juraj.linkes <jlinkes@cisco.com>
Diffstat (limited to 'testing/robot')
-rw-r--r--testing/robot/lib/FDSLibrary.py51
-rw-r--r--testing/robot/lib/Keywords.robot4
-rw-r--r--testing/robot/sec_groups_and_l2-smoke.robot8
3 files changed, 39 insertions, 24 deletions
diff --git a/testing/robot/lib/FDSLibrary.py b/testing/robot/lib/FDSLibrary.py
index 0d0929e..829bbcb 100644
--- a/testing/robot/lib/FDSLibrary.py
+++ b/testing/robot/lib/FDSLibrary.py
@@ -7,7 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from keystoneauth1 import loading
+from keystoneauth1.identity import v2, v3
from keystoneauth1 import session
from glanceclient import client as glance
from neutronclient.v2_0 import client as neutron
@@ -22,19 +22,25 @@ import subprocess
class FDSLibrary():
def __init__(self):
- auth_obj = loading.get_plugin_loader('password').load_from_options(auth_url=os.getenv('OS_AUTH_URL'),
- username=os.getenv('OS_USERNAME'),
- password=os.getenv('OS_PASSWORD'),
- project_id=os.getenv('OS_PROJECT_ID'))
+ if os.getenv('OS_IDENTITY_API_VERSION') == '3':
+ auth = v3.Password(auth_url=os.getenv('OS_AUTH_URL'),
+ username=os.getenv('OS_USERNAME'),
+ password=os.getenv('OS_PASSWORD'),
+ project_id=os.getenv('OS_PROJECT_ID'),
+ user_domain_name=os.getenv('OS_USER_DOMAIN_NAME'))
+ else:
+ auth = v2.Password(username=os.getenv('OS_USERNAME'),
+ password=os.getenv('OS_PASSWORD'),
+ tenant_name=os.getenv('OS_TENANT_NAME'),
+ auth_url=os.getenv('OS_AUTH_URL'))
+
+ sess = session.Session(auth=auth)
logger.debug("Initializing glance client.")
- self.glance_client = glance.Client('2', session=session.Session(auth=auth_obj))
+ self.glance_client = glance.Client('2', session=sess)
logger.debug("Initializing neutron client.")
- self.neutron_client = neutron.Client(username=os.getenv('OS_USERNAME'),
- password=os.getenv('OS_PASSWORD'),
- tenant_name=os.getenv('OS_TENANT_NAME'),
- auth_url=os.getenv('OS_AUTH_URL'))
+ self.neutron_client = neutron.Client(session=sess)
logger.debug("Initializing nova client.")
- self.nova_client = nova.Client('2', session=session.Session(auth=auth_obj))
+ self.nova_client = nova.Client('2', session=sess)
def check_flavor_exists(self):
flavor_names = [x for x in self.nova_client.flavors.list(min_ram=760)]
@@ -104,17 +110,22 @@ class FDSLibrary():
response = self.nova_client.servers.create(name=name, image=image.id, flavor=flavor.id,
security_groups=security_groups, nics=nics,
userdata=userdata)
- for key in dir(response):
- print key, getattr(response, key)
return response
def format_string(self, string, substitute):
return string.format(substitute)
- def check_server_console(self, vm_id, string):
+ def _check_vm_is_active(self, vm_id):
vm_obj = self.nova_client.servers.get(vm_id)
- timeout = 0
- while timeout < 100:
+ if getattr(vm_obj, 'OS-EXT-STS:vm_state', None) != 'active':
+ raise Exception("VM with id '{}' is not active".format(vm_id))
+
+ def check_server_console(self, vm_id, string, timeout=300):
+ self._check_vm_is_active(vm_id)
+ vm_obj = self.nova_client.servers.get(vm_id)
+ start = datetime.datetime.now()
+ delta = datetime.timedelta(seconds=timeout)
+ while datetime.datetime.now() - start < delta:
console_out = vm_obj.get_console_output()
print "console output is: '{}'".format(console_out[-200:])
failed_to_read_metadata = 'failed to read iid from metadata'
@@ -125,7 +136,6 @@ class FDSLibrary():
elif failed_to_read_metadata in console_out:
print failed_to_read_metadata
return False
- timeout += 1
time.sleep(5)
return False
@@ -167,12 +177,15 @@ class FDSLibrary():
while datetime.datetime.now() - start < delta and self._states_are_not_equal(current_state, status):
time.sleep(1)
vm_obj = self.nova_client.servers.get(vm_id)
- current_state = getattr(vm_obj, 'OS-EXT-STS:vm_state', None)
print "Found state '{}' while looking for state '{}'".format(current_state, status)
+ current_state = getattr(vm_obj, 'OS-EXT-STS:vm_state', None)
+ if current_state == 'error':
+ raise Exception("Vm with id '{}' is in state '{}' after {} seconds"
+ "".format(vm_id, current_state, (datetime.datetime.now() - start).seconds))
if self._states_are_not_equal(current_state, status):
raise Exception("Vm with id '{}' is in state '{}' after timeout of {} seconds"
- "".format(vm_id, getattr(vm_obj, 'OS-EXT-STS:vm_state'), timeout))
+ "".format(vm_id, current_state, timeout))
except NotFound as e:
if status is not None:
raise e
diff --git a/testing/robot/lib/Keywords.robot b/testing/robot/lib/Keywords.robot
index d9d9cb1..6828672 100644
--- a/testing/robot/lib/Keywords.robot
+++ b/testing/robot/lib/Keywords.robot
@@ -72,8 +72,8 @@ Create security group rules
log many &{response}
Create port with ip
- [Arguments] ${port_name} ${ip_address}
- &{response} = create port ${port_name} ${network_id} ${subnet_id} ${ip_address}
+ [Arguments] ${port_name} ${ip_address} ${security_groups}
+ &{response} = create port ${port_name} ${network_id} ${subnet_id} ${ip_address} ${security_groups}
log many &{response}
log ${response.port['id']}
[Return] ${response.port['id']}
diff --git a/testing/robot/sec_groups_and_l2-smoke.robot b/testing/robot/sec_groups_and_l2-smoke.robot
index 347c78c..6dd3166 100644
--- a/testing/robot/sec_groups_and_l2-smoke.robot
+++ b/testing/robot/sec_groups_and_l2-smoke.robot
@@ -38,11 +38,13 @@ Create sec rules
Wait Until Keyword Succeeds 3x 3s create security rule ${SEC_GR_SERVER} ingress ipv4 proto=icmp
Create port for VM1
- ${result} = Create port with ip ${port1_name} ${vm1_address}
+ ${security_groups} = Create List ${SEC_GR_SERVER}
+ ${result} = Create port with ip ${port1_name} ${vm1_address} ${security_groups}
Set Suite Variable ${port1_id} ${result}
Create port for VM2
- ${result} = Create port with ip ${port2_name} ${vm2_address}
+ ${security_groups} = Create List ${SEC_GR_CLIENT}
+ ${result} = Create port with ip ${port2_name} ${vm2_address} ${security_groups}
Set Suite Variable ${port2_id} ${result}
Create VM1
@@ -56,7 +58,7 @@ Wait for VM1 to be active
Create VM2
${port_ids} = Create List ${port2_id}
- ${result} = Create vm ${vm2_name} ${port_ids} flavor=${flavor_to_use} userdata=${userdata2}
+ ${result} = Create vm ${vm2_name} ${port_ids} userdata=${userdata2}
Set Suite Variable ${vm2_id} ${result}
Wait for VM2 to be active