diff options
author | 2017-03-07 12:03:11 +0100 | |
---|---|---|
committer | 2017-03-07 16:52:33 +0100 | |
commit | 251655730cd037a9bd5dbbb42ba07cb64bacde88 (patch) | |
tree | a35985a089c026f97e0385d88f741466e7a257f0 /testing/robot/lib/FDSLibrary.py | |
parent | 27f4d1c945814b2dc127c06ec35feeed4d9d432a (diff) |
Improving robot smoke test
Suite setup modified:
- flavor is checked and created if it does not exist
- image is checked and created if it does not exist
Change-Id: I0254827034fcb2e1a7f5f0983b5a5bad29eada43
Signed-off-by: Tomas Cechvala <tcechval@cisco.com>
Diffstat (limited to 'testing/robot/lib/FDSLibrary.py')
-rw-r--r-- | testing/robot/lib/FDSLibrary.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/testing/robot/lib/FDSLibrary.py b/testing/robot/lib/FDSLibrary.py index 0cb43ee..3d19680 100644 --- a/testing/robot/lib/FDSLibrary.py +++ b/testing/robot/lib/FDSLibrary.py @@ -7,21 +7,33 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from keystoneauth1 import loading +from keystoneauth1 import session +from glanceclient import client as glance from neutronclient.v2_0 import client as neutron from novaclient import client as nova from novaclient.exceptions import NotFound +from robot.api import logger import time import datetime import os import subprocess + class FDSLibrary(): def __init__(self): + logger.debug("Initializing glance client.") + self.glance_client = glance.Client('2', session=session.Session( + auth=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')))) + 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')) - + logger.debug("Initializing nova client.") self.nova_client = nova.Client('2', os.getenv('OS_USERNAME'), os.getenv('OS_PASSWORD'), @@ -32,10 +44,25 @@ class FDSLibrary(): flavor_list_names = [x.name for x in self.nova_client.flavors.list()] return flavor in flavor_list_names + def create_flavor(self, name, ram, vcpus="1", disk="0"): + response = self.nova_client.flavors.create(name, ram, vcpus, disk) + return response + def check_image_exists(self, image): - image_list_names = [x.name for x in self.nova_client.images.list()] + image_list_names = [x.name for x in self.glance_client.images.list()] return image in image_list_names + def create_image(self, image_name, file_path, disk="qcow2", + container="bare", public="public", property="hw_mem_page_size=large"): + image = self.glance_client.images.create(name=image_name, + visibility=public, + disk_format=disk, + container_format=container, + property=property) + with open(file_path) as image_data: + self.glance_client.images.upload(image.id, image_data) + return image.id + def create_network(self, name): body = {'network': {'name': name}} response = self.neutron_client.create_network(body=body) |