Improving robot smoke test 17/29917/3
authorTomas Cechvala <tcechval@cisco.com>
Tue, 7 Mar 2017 11:03:11 +0000 (12:03 +0100)
committerTomas Cechvala <tcechval@cisco.com>
Tue, 7 Mar 2017 15:52:33 +0000 (16:52 +0100)
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>
testing/robot/data/test_data.py
testing/robot/lib/FDSLibrary.py
testing/robot/smoke.robot

index d78ce4f..2011257 100644 (file)
@@ -20,7 +20,7 @@ port1_name = 'fds_smoke_port1_' + run_uuid
 port2_name = 'fds_smoke_port2_' + run_uuid
 subnet_cidr = '192.168.10.0/24'
 vm_flavor = 'm1.small'
-vm_image = 'cirros-0.3.3'
+vm_image = 'cirros-0.3.4'
 userdata1 = "#!/bin/sh\n\nsudo ip a add {}/24 dev eth0\n".format(vm1_address)
 userdata2 = "#!/bin/sh\n\nsudo ip a add {}/24 dev eth0\nwhile true; do\n ping -c 1 {} 2>&1 >/dev/null\n " \
             "RES=$?\n if [ \"Z$RES\" = \"Z0\" ] ; then\n  echo 'ping PASSED'\n break\n else\n  echo " \
index 0cb43ee..3d19680 100644 (file)
@@ -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)
index fddac5d..a6c7d70 100644 (file)
@@ -61,12 +61,8 @@ Setup Suite
     Set Suite Variable  ${port2_id}     ${None}
     Set Suite Variable  ${vm1_id}       ${None}
     Set Suite Variable  ${vm2_id}       ${None}
-    ${result} =     Check Flavor Exists     ${vm_flavor}
-    Log     ${vm_flavor}
-    Should be True      ${result}
-    ${result} =     Check Image Exists  ${vm_image}
-    Log     ${vm_image}
-    Should be True      ${result}
+    Ensure Image
+    Ensure Flavor
 
 Teardown Suite
     Run Keyword If  $vm1_id is not $None        Delete vm       ${vm1_id}
@@ -75,6 +71,20 @@ Teardown Suite
     Run Keyword If  $port2_id is not $None      Delete ports    ${port2_id}
     Run Keyword If  $network_id is not $None    Delete network  ${network_id}
 
+Ensure Flavor
+    ${result} =     Check Flavor Exists     ${vm_flavor}
+    Return From Keyword If  '${result}' == 'True'
+    Create Flavor  ${vm_flavor}  ram=768
+    ${result} =     Check Flavor Exists     ${vm_flavor}
+    Should be True      ${result}
+
+Ensure Image
+    ${result} =     Check Image Exists  ${vm_image}
+    Return From Keyword If  '${result}' == 'True'
+    Create Image  ${vm_image}  /home/opnfv/functest/data/cirros-0.3.4-x86_64-disk.img
+    ${result} =     Check Image Exists  ${vm_image}
+    Should be True      ${result}
+
 Create tenant network
     &{response} =   create network  ${network_name}
     log many    &{response}