X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwcal%2Ftest%2Ftest_rwcal_openstack.py;h=6b0a24723c1ce26f144b52145e83bc153e46e35a;hb=af804410b4063fe28658e38d23e3108b1d88a799;hp=960beb9f7f94a0af774d2c9b436e2fc2969ccec5;hpb=d748ab1836d94ebe1273b1910954be3b2a2b4486;p=osm%2FSO.git diff --git a/rwcal/test/test_rwcal_openstack.py b/rwcal/test/test_rwcal_openstack.py index 960beb9f..6b0a2472 100644 --- a/rwcal/test/test_rwcal_openstack.py +++ b/rwcal/test/test_rwcal_openstack.py @@ -20,7 +20,6 @@ import logging import time import unittest import hashlib - import novaclient.exceptions as nova_exception import paramiko import rw_peas @@ -29,10 +28,17 @@ from keystoneclient import v3 as ksclient from gi.repository import RwcalYang from gi.repository.RwTypes import RwStatus -from rift.rwcal.openstack.openstack_drv import KeystoneDriver, NovaDriver +from rift.rwcal.openstack.openstack_drv import KeystoneDriver, NovaDriver, KeystoneDriverV3, KeystoneDriverV2 logger = logging.getLogger('rwcal-openstack') +PING_USERDATA = ''' +#cloud-config +password: fedora +chpasswd: { expire: False } +ssh_pwauth: True +''' + # # Important information about openstack installation. This needs to be manually verified # @@ -46,7 +52,22 @@ openstack_info = { 'reserved_image' : 'Fedora-x86_64-20-20131211.1-sda-ping.qcow2', 'physical_network' : None, 'network_type' : None, - 'segmentation_id' : None + 'segmentation_id' : None, + 'user_domain_name' : 'default', + 'project_domain_name': 'default' + } + +openstack_V3_info = { + 'username' : 'riftdev_admin', + 'password' : 'mypasswd', + 'auth_url' : 'http://10.68.0.11:5000/v3/', + 'project_name' : 'demov3', + 'mgmt_network' : 'center', + 'physical_network' : None, + 'network_type' : None, + 'segmentation_id' : None, + 'user_domain_name' : 'riftdev', + 'project_domain_name': 'riftdev' } @@ -54,14 +75,16 @@ def get_cal_account(): """ Creates an object for class RwcalYang.CloudAccount() """ - account = RwcalYang.CloudAccount() - account.name = "Gruntxx" - account.account_type = "openstack" - account.openstack.key = openstack_info['username'] - account.openstack.secret = openstack_info['password'] - account.openstack.auth_url = openstack_info['auth_url'] - account.openstack.tenant = openstack_info['project_name'] - account.openstack.mgmt_network = openstack_info['mgmt_network'] + account = RwcalYang.CloudAccount() + account.name = "Gruntxx" + account.account_type = "openstack" + account.openstack.key = openstack_info['username'] + account.openstack.secret = openstack_info['password'] + account.openstack.auth_url = openstack_info['auth_url'] + account.openstack.tenant = openstack_info['project_name'] + account.openstack.mgmt_network = openstack_info['mgmt_network'] + account.openstack.user_domain = openstack_info['user_domain_name'] + account.openstack.project_domain = openstack_info['project_domain_name'] return account def get_cal_plugin(): @@ -531,6 +554,7 @@ class OpenStackTest(unittest.TestCase): openstack_info['username'], openstack_info['password'], openstack_info['auth_url'], + None, openstack_info['project_name']) # Get hold of the client instance need for Token Manager client = drv._get_keystone_connection() @@ -566,6 +590,81 @@ class OpenStackTest(unittest.TestCase): flavors = nova.flavor_list() self.assertTrue(len(flavors) > 1) + def test_v3_Keystone(self): + # Keystone v3 authentication + auth_exp = False + try: + drv = KeystoneDriverV3(openstack_V3_info['username'], + openstack_V3_info['password'], + openstack_V3_info['auth_url'], + openstack_V3_info['project_name'], + None, + openstack_V3_info['user_domain_name'], + openstack_V3_info['project_domain_name']) + client = drv._get_keystone_connection() + except Exception: + auth_exp = True + self.assertFalse(auth_exp) + + # Incorrect domain being to passed to v3 Keystone API + auth_exp = False + try: + drv = KeystoneDriverV3(openstack_V3_info['username'], + openstack_V3_info['password'], + openstack_V3_info['auth_url'], + openstack_V3_info['project_name'], + None, + "DummyDom", + openstack_V3_info['project_domain_name']) + client = drv._get_keystone_connection() + except Exception: + auth_exp = True + self.assertTrue(auth_exp) + + # Keystone v3 authentication-Backward compatabilty test + auth_exp = False + try: + drv = KeystoneDriverV3(openstack_info['username'], + openstack_info['password'], + openstack_info['auth_url'], + openstack_info['project_name'], + None, + openstack_info['user_domain_name'], + openstack_info['project_domain_name']) + client = drv._get_keystone_connection() + except Exception: + auth_exp = True + self.assertFalse(auth_exp) + + # Keystone v3 authentication-Backward compatabilty + auth_exp = False + try: + drv = KeystoneDriverV3(openstack_info['username'], + openstack_info['password'], + openstack_info['auth_url'], + openstack_info['project_name'], + None, + None, + None) + client = drv._get_keystone_connection() + except Exception: + auth_exp = True + self.assertFalse(auth_exp) + + # Keystone v2 authentication + auth_exp = False + try: + drv2 = KeystoneDriverV2( + openstack_info['username'], + openstack_info['password'], + 'http://10.66.4.17:5000/v2.0', + openstack_info['project_name'], + None) + client = drv2._get_keystone_connection() + except Exception: + auth_exp = True + self.assertFalse(auth_exp) + @unittest.skip("Skipping test_vm_operations") def test_vm_operations(self): """ @@ -831,8 +930,23 @@ class OpenStackTest(unittest.TestCase): vdu.node_id = OpenStackTest.NodeID vdu.image_id = self._image.id vdu.flavor_id = self._flavor.id - vdu.vdu_init.userdata = '' + vdu.vdu_init.userdata = PING_USERDATA vdu.allocate_public_address = True + meta1 = vdu.supplemental_boot_data.custom_meta_data.add() + meta1.name = "EMS_IP" + meta1.data_type = "STRING" + meta1.value = "10.5.6.6" + #meta2 = vdu.supplemental_boot_data.custom_meta_data.add() + #meta2.name = "Cluster_data" + #meta2.data_type = "JSON" + #meta2.value = '''{ "cluster_id": "12" , "vnfc_id": "112" }''' + #vdu.supplemental_boot_data.boot_data_drive = True + customfile1 = vdu.supplemental_boot_data.config_file.add() + customfile1.source = "abcdef124" + customfile1.dest = "/tmp/tempfile.txt" + customfile2 = vdu.supplemental_boot_data.config_file.add() + customfile2.source = "123456" + customfile2.dest = "/tmp/tempfile2.txt" c1 = vdu.connection_points.add() c1.name = "c_point1" c1.virtual_link_id = virtual_link_id @@ -851,7 +965,7 @@ class OpenStackTest(unittest.TestCase): return vdu - #@unittest.skip("Skipping test_create_delete_virtual_link_and_vdu") + @unittest.skip("Skipping test_create_delete_virtual_link_and_vdu") def test_create_delete_virtual_link_and_vdu(self): """ Test to create VDU @@ -934,6 +1048,115 @@ class OpenStackTest(unittest.TestCase): logger.info("Openstack-CAL-Test: VDU/Virtual Link create-delete test successfully completed") + def _get_vol_vdu_request_info(self, vlink_list): + """ + Returns object of type RwcalYang.VDUInitParams + """ + vdu = RwcalYang.VDUInitParams() + vdu.name = "cal_vdu" + vdu.flavor_id = self._flavor.id + vdu.allocate_public_address = True + ctr = 0 + for vl in vlink_list: + c1 = vdu.connection_points.add() + c1.name = "c_point" + str(ctr) + ctr += 1 + c1.virtual_link_id = vl + c1.type_yang = 'VIRTIO' + + vol0 = vdu.volumes.add() + vol0.name = "vda" + vol0.image = openstack_info['reserved_image'] + vol0.size = 10 + vol0.boot_priority = 0 + vol0.device_type = "disk" + meta1 = vol0.custom_meta_data.add() + meta1.name = "fs_type" + meta1.data_type = "STRING" + meta1.value = "ext4" + + return vdu + + #@unittest.skip("Skipping test_create_vol_vdu") + def test_create_vol_vdu(self): + """ + Test to create VDU with mgmt port using Volumes + """ + logger.info("Openstack-CAL-Test: Test Create Virtual Link API") + vlink_list = [] + vlink = RwcalYang.VirtualLinkReqParams() + vlink.name = 'rift.cal.virtual_link' + vlink.subnet = '11.0.1.0/24' + + rc, rsp = self.cal.create_virtual_link(self._acct, vlink) + self.assertEqual(rc.status, RwStatus.SUCCESS) + logger.info("Openstack-CAL-Test: Created virtual_link with Id: %s" %rsp) + vlink_id = rsp + + #Check if virtual_link create is successful + rc, rsp = self.cal.get_virtual_link(self._acct, rsp) + self.assertEqual(rc, RwStatus.SUCCESS) + self.assertEqual(rsp.virtual_link_id, vlink_id) + vlink_list.append(vlink_id) + + # Now create VDU + vdu_req = self._get_vol_vdu_request_info(vlink_list) + logger.info("################################### ") + logger.info("Openstack-CAL-Test: Test Create VDU API (w/ volumes) ") + + rc, rsp = self.cal.create_vdu(self._acct, vdu_req) + logger.debug("Openstack-CAL-Test: rc %s rsp %s" % (rc, rsp)) + self.assertEqual(rc.status, RwStatus.SUCCESS) + logger.info("Openstack-CAL-Test: Created vdu with Id: %s" %rsp) + + test_vdu_id = rsp + + ## Check if VDU get is successful + rc, rsp = self.cal.get_vdu(self._acct, test_vdu_id) + logger.debug("Get VDU response %s", rsp) + self.assertEqual(rsp.vdu_id, test_vdu_id) + + ### Wait until vdu_state is active + logger.debug("Waiting 10 secs") + time.sleep(10) + #{'name': 'dp0vhost7', 'connection_point_id': 'dp0vhost7', 'state': 'active', 'virtual_link_id': 'rift.cal.virtual_link', 'ip_address': '192.168.100.6'} + vdu_state = 'inactive' + cp_state = 'inactive' + for i in range(5): + rc, rsp = self.cal.get_vdu(self._acct, test_vdu_id) + self.assertEqual(rc, RwStatus.SUCCESS) + logger.info("Openstack-CAL-Test: VDU with id : %s. Reached State : %s, mgmt ip %s" %(test_vdu_id, rsp.state, rsp.management_ip)) + if (rsp.state == 'active') and ('management_ip' in rsp) and ('public_ip' in rsp): + vdu_state = 'active' + #'connection_points': [{'name': 'dp0vhost7', 'connection_point_id': 'dp0vhost7', 'state': 'active', 'virtual_link_id': 'rift.cal.virtual_link', 'ip_address': '192.168.100.6'}] + for cp in rsp.connection_points: + logger.info("Openstack-CAL-Test: VDU with id : %s. Reached State : %s CP state %s" %(test_vdu_id, rsp.state, cp)) + if vdu_state == 'active' and cp.ip_address is not None : + cp_state = 'active' + break + logger.debug("Waiting another 5 secs") + time.sleep(5) + + self.assertEqual(rc, RwStatus.SUCCESS) + self.assertEqual(rsp.state, 'active') + self.assertEqual(vdu_state, 'active') + self.assertEqual(cp_state, 'active') + logger.info("Openstack-CAL-Test: VDU with id : %s reached expected state : %s IP: %s" %(test_vdu_id, rsp.state, rsp.management_ip)) + logger.info("Openstack-CAL-Test: VDUInfo: %s" %(rsp)) + logger.info("Waiting for 30 secs before deletion") + time.sleep(30) + + ### Check vdu list as well + rc, rsp = self.cal.get_vdu_list(self._acct) + self.assertEqual(rc, RwStatus.SUCCESS) + found = False + logger.debug("Get VDU response %s", rsp) + for vdu in rsp.vdu_info_list: + if vdu.vdu_id == test_vdu_id: + found = True + self.assertEqual(found, True) + logger.info("Openstack-CAL-Test: Passed VDU list" ) + class VmData(object): """A convenience class that provides all the stats and EPA Attributes from the VM provided @@ -1060,5 +1283,6 @@ class VmData(object): if __name__ == "__main__": - logging.basicConfig(level=logging.DEBUG) + #logging.basicConfig(level=logging.DEBUG) + logger.setLevel(logging.DEBUG) unittest.main()