def test_55_alter(self, get_driver): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{ 'id': 'libcloud', 'type': 'LibCloud', 'username': '******', 'password': '******', 'driver': 'EC2' }]) lib_cloud = self.get_lib_cloud() inf = MagicMock() vm = VirtualMachine(inf, "1", lib_cloud.cloud, radl, radl, lib_cloud, 1) driver = MagicMock() get_driver.return_value = driver node = MagicMock() node.id = "1" node.driver = driver driver.list_nodes.return_value = [node] node_size = MagicMock() node_size.ram = 2048 node_size.price = 2 node_size.disk = 1 node_size.vcpus = 2 node_size.name = "medium" driver.list_sizes.return_value = [node_size] driver.ex_resize.return_value = True success, _ = lib_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_empty_contextualize(self): radl = """ system test ( cpu.count>=1 ) deploy test 1 contextualize () """ r = parse_radl(radl) r.check() self.assertEqual(r.contextualize.items, {}) radl_json = dump_radl_json(r) r = parse_radl_json(radl_json) r.check() self.assertEqual(r.contextualize.items, {}) radl = """ system test ( cpu.count>=1 ) deploy test 1 """ r = parse_radl(radl) r.check() self.assertEqual(r.contextualize.items, None) radl_json = dump_radl_json(r) r = parse_radl_json(radl_json) r.check() self.assertEqual(r.contextualize.items, None)
def test_15_get_vm_info(self): """ Test the GetVMInfo IM function """ before = time.time() (success, vm_ids) = self.server.GetInfrastructureInfo( self.inf_id, self.auth_data) resp_time = time.time() - before self.__class__.response_times.append(resp_time) self.assertTrue( success, msg="ERROR calling GetInfrastructureInfo: " + str(vm_ids)) before = time.time() (success, info) = self.server.GetVMInfo( self.inf_id, vm_ids[0], self.auth_data) resp_time = time.time() - before self.__class__.response_times.append(resp_time) self.assertTrue(success, msg="ERROR calling GetVMInfo: " + str(info)) try: radl_parse.parse_radl(info) except Exception as ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetVMInfo: " + str(ex)) self.wait()
def test_setIps(self): radl_data = """ system test ( )""" radl = radl_parse.parse_radl(radl_data) vm = VirtualMachine(None, "1", None, radl, radl) public_ips = ['158.42.1.1'] private_ips = ['10.0.0.1'] vm.setIps(public_ips, private_ips) self.assertEqual(vm.info.systems[0].getValue('net_interface.1.ip'), "10.0.0.1") self.assertEqual(vm.info.systems[0].getValue('net_interface.0.ip'), "158.42.1.1") radl_data = """ network net1 (cidr = '10.0.0.1') system test ( net_interface.0.connection = 'net1' )""" radl = radl_parse.parse_radl(radl_data) private_ips = ['192.168.0.1', '10.0.0.1'] vm = VirtualMachine(None, "1", None, radl, radl) vm.setIps(public_ips, private_ips) self.assertEqual(vm.info.systems[0].getValue('net_interface.0.ip'), "10.0.0.1") self.assertEqual(vm.info.systems[0].getValue('net_interface.2.ip'), "192.168.0.1")
def test_get_vm_info(self): """ Test GetVMInfo and GetVMProperty and GetVMContMsg and GetInfrastructureRADL and GetInfrastructureContMsg and GetInfrastructureState. """ radl = RADL() radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("disk.0.os.credentials.password", "=", "pass")])) radl.add(deploy("s0", 1)) auth0 = self.getAuth([0], [], [("Dummy", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) radl_info = IM.GetVMInfo(infId, "0", auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual(parsed_radl_info.systems[0].getValue("state"), "running") state = IM.GetVMProperty(infId, "0", "state", auth0) self.assertEqual(state, "running") contmsg = IM.GetVMContMsg(infId, "0", auth0) self.assertEqual(contmsg, "") contmsg = IM.GetInfrastructureContMsg(infId, auth0) state = IM.GetInfrastructureState(infId, auth0) self.assertEqual(state["state"], "running") self.assertEqual(state["vm_states"]["0"], "running") radl_info = IM.GetInfrastructureRADL(infId, auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual(parsed_radl_info.systems[0].getValue("disk.0.os.credentials.username"), "user") IM.DestroyInfrastructure(infId, auth0)
def test_15_get_vm_info(self): """ Test the GetVMInfo IM function """ before = time.time() (success, vm_ids) = self.server.GetInfrastructureInfo( self.inf_id, self.auth_data) resp_time = time.time() - before self.__class__.response_times.append(resp_time) self.assertTrue( success, msg="ERROR calling GetInfrastructureInfo: " + str(vm_ids)) before = time.time() (success, info) = self.server.GetVMInfo( self.inf_id, vm_ids[0], self.auth_data) resp_time = time.time() - before self.__class__.response_times.append(resp_time) self.assertTrue(success, msg="ERROR calling GetVMInfo: " + str(info)) try: radl_parse.parse_radl(info) except Exception, ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetVMInfo: " + str(ex))
def test_55_alter(self, get_driver): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'ost', 'type': 'OpenStack', 'username': '******', 'password': '******', 'tenant': 'tenant', 'host': 'https://server.com:5000'}]) ost_cloud = self.get_ost_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", ost_cloud.cloud, radl, radl, ost_cloud) driver = MagicMock() get_driver.return_value = driver node = MagicMock() node.id = "1" node.state = "running" node.extra = {'flavorId': 'small'} node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver driver.list_nodes.return_value = [node] node_size = MagicMock() node_size.ram = 2048 node_size.price = 1 node_size.disk = 1 node_size.vcpus = 2 node_size.name = "small" driver.list_sizes.return_value = [node_size] driver.ex_resize.return_value = True success, _ = ost_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_get_vm_info(self): """ Test GetVMInfo and GetVMProperty and GetVMContMsg and GetInfrastructureRADL and GetInfrastructureContMsg and GetInfrastructureState. """ radl = RADL() radl.add( system("s0", [ Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("disk.0.os.credentials.password", "=", "pass") ])) radl.add(deploy("s0", 1)) auth0 = self.getAuth([0], [], [("Dummy", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) radl_info = IM.GetVMInfo(infId, "0", auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual(parsed_radl_info.systems[0].getValue("state"), "running") radl_info = IM.GetVMInfo(infId, "0", auth0, True) parsed_radl_info = parse_radl_json(radl_info) self.assertEqual(parsed_radl_info.systems[0].getValue("state"), "running") state = IM.GetVMProperty(infId, "0", "state", auth0) self.assertEqual(state, "running") contmsg = IM.GetVMContMsg(infId, "0", auth0) self.assertEqual(contmsg, "") InfrastructureList.infrastructure_list[infId].cont_out = "Header" InfrastructureList.infrastructure_list[infId].vm_list[ 0].cloud_connector = MagicMock() InfrastructureList.infrastructure_list[infId].vm_list[ 0].cloud_connector.error_messages = "TESTMSG" contmsg = IM.GetInfrastructureContMsg(infId, auth0) header_contmsg = IM.GetInfrastructureContMsg(infId, auth0, True) InfrastructureList.infrastructure_list[infId].vm_list[ 0].cloud_connector = None self.assertIn("TESTMSG", contmsg) self.assertNotIn("TESTMSG", header_contmsg) self.assertIn("Header", header_contmsg) state = IM.GetInfrastructureState(infId, auth0) self.assertEqual(state["state"], "running") self.assertEqual(state["vm_states"]["0"], "running") radl_info = IM.GetInfrastructureRADL(infId, auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual( parsed_radl_info.systems[0].getValue( "disk.0.os.credentials.username"), "user") IM.DestroyInfrastructure(infId, auth0)
def test_34_get_radl(self): resp = self.create_request("GET", "/infrastructures/" + self.inf_id + "/radl") self.assertEqual(resp.status_code, 200, msg="ERROR getting the infrastructure RADL:" + resp.text) try: radl_parse.parse_radl(resp.text) except Exception as ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetInfrastructureRADL: " + str(ex))
def test_55_alter(self, server_proxy): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m and disk.1.size=1GB and disk.1.device='hdc' and disk.1.fstype='ext4' and disk.1.mount_path='/mnt/disk' )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{ 'id': 'one', 'type': 'OpenNebula', 'username': '******', 'password': '******', 'host': 'server.com:2633' }]) one_cloud = self.get_one_cloud() inf = MagicMock() vm = VirtualMachine(inf, "1", one_cloud.cloud, radl, radl, one_cloud, 1) one_server = MagicMock() one_server.one.vm.action.return_value = (True, "", 0) one_server.one.vm.resize.return_value = (True, "", 0) one_server.one.vm.info.return_value = ( True, read_file_as_string("files/vm_info_off.xml"), 0) one_server.one.vm.attach.return_value = (True, "", 0) one_server.system.listMethods.return_value = ["one.vm.resize"] server_proxy.return_value = one_server success, _ = one_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_55_alter(self, get_driver): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'ost', 'type': 'OpenStack', 'username': '******', 'password': '******', 'tenant': 'tenant', 'host': 'https://server.com:5000'}]) ost_cloud = self.get_ost_cloud() inf = MagicMock() vm = VirtualMachine(inf, "1", ost_cloud.cloud, radl, radl, ost_cloud, 1) driver = MagicMock() get_driver.return_value = driver node = MagicMock() node.id = "1" node.state = "running" node.extra = {'flavorId': 'small'} node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver driver.ex_get_node_details.return_value = node node_size = MagicMock() node_size.ram = 2048 node_size.price = 1 node_size.disk = 1 node_size.vcpus = 2 node_size.name = "small" driver.list_sizes.return_value = [node_size] driver.ex_resize.return_value = True success, _ = ost_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_55_alter(self, get_connection): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{ 'id': 'ec2', 'type': 'EC2', 'username': '******', 'password': '******' }]) ec2_cloud = self.get_ec2_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "us-east-1;sid-1", ec2_cloud.cloud, radl, radl, ec2_cloud) conn = MagicMock() get_connection.return_value = conn reservation = MagicMock() instance = MagicMock() instance.update.return_value = True instance.stop.return_value = True instance.state = "stopped" reservation.instances = [instance] conn.get_all_instances.return_value = [reservation] success, _ = ec2_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_ansible_host(self): radl = """ ansible ansible_master (host = 'host' and credentials.username = '******' and credentials.password = '******') network net () system main ( ansible_host = 'ansible_master' and net_interface.0.connection = 'net' ) """ r = parse_radl(radl) self.radl_check(r) radl_json = dump_radl_json(r) r = parse_radl_json(radl_json) self.radl_check(r) radl = """ ansible ansible_master (host = 'host' and credentials.username = '******' and credentials.password = '******') network net () system main ( ansible_host = 'ansible_master1' and net_interface.0.connection = 'net' ) """ r = parse_radl(radl) with self.assertRaises(RADLParseException): self.radl_check(r) radl = """ ansible ansible_master (credentials.username = '******' and credentials.password = '******') network net () system main ( net_interface.0.connection = 'net' ) """ r = parse_radl(radl) with self.assertRaises(RADLParseException): self.radl_check(r) radl = """ ansible ansible_master (host = 'host' and credentials.username = '******') network net () system main ( net_interface.0.connection = 'net' ) """ r = parse_radl(radl) with self.assertRaises(RADLParseException): self.radl_check(r)
def test_34_get_radl(self): self.server.request('GET', "/infrastructures/" + self.inf_id + "/radl", headers={'AUTHORIZATION': self.auth_data}) resp = self.server.getresponse() output = str(resp.read()) self.assertEqual(resp.status, 200, msg="ERROR getting the infrastructure RADL:" + output) try: radl_parse.parse_radl(output) except Exception, ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetInfrastructureRADL: " + str(ex))
def test_55_alter(self, delete_proxy, get_keystone_uri, connection): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( disk.1.size=1GB and disk.1.device='hdc' and disk.1.fstype='ext4' and disk.1.mount_path='/mnt/disk' )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{ 'id': 'occi', 'type': 'OCCI', 'proxy': 'proxy', 'host': 'https://server.com:11443' }]) occi_cloud = self.get_occi_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", occi_cloud.cloud, radl, radl, occi_cloud) conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.getresponse.side_effect = self.get_response get_keystone_uri.return_value = None success, _ = occi_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_12_getradl(self): """ Test the GetInfrastructureRADL IM function """ (success, res) = self.server.GetInfrastructureRADL( self.inf_id, self.auth_data) self.assertTrue( success, msg="ERROR calling GetInfrastructureRADL: " + str(res)) try: radl_parse.parse_radl(res) except Exception, ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetInfrastructureRADL: " + str(ex))
def test_55_alter(self, sleep, connection): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{ 'id': 'azure', 'type': 'Azure', 'username': '******', 'public_key': 'public_key', 'private_key': 'private_key' }]) azure_cloud = self.get_azure_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", azure_cloud.cloud, radl, radl, azure_cloud) conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.getresponse.side_effect = self.get_response success, _ = azure_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_55_alter(self, connection): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{ 'id': 'fogbow', 'type': 'Kubernetes', 'host': 'http://server.com:8080' }]) kube_cloud = self.get_kube_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "namespace/1", kube_cloud.cloud, radl, radl, kube_cloud) conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.putrequest.side_effect = self.request conn.getresponse.side_effect = self.get_response success, _ = kube_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_format_output(self, get_media_type): get_media_type.return_value = ["application/json"] radl = parse_radl("system test (cpu.count = 1)") info = format_output(radl) info = json.loads(info) self.assertEqual(info, [{ "cpu.count": 1, "class": "system", "id": "test" }]) info = format_output(radl, field_name="radl") info = json.loads(info) self.assertEqual( info, {"radl": [{ "cpu.count": 1, "class": "system", "id": "test" }]}) radl = parse_radl( "system test ( disk.0.applications contains (name='test'))") res = list(radl.systems[0].props.values())[0] info = format_output(res, field_name="cont") info = json.loads(info) self.assertEqual(info, {"cont": {"test": {"name": "test"}}}) info = format_output(["1", "2"]) info = json.loads(info) self.assertEqual(info, ["1", "2"]) get_media_type.return_value = ["text/*"] info = format_output(["1", "2"], field_name="cont", default_type="application/json") info = json.loads(info) self.assertEqual(info, {"cont": ["1", "2"]}) info = format_output(["1", "2"]) self.assertEqual(info, '1\n2') info = format_output(u'contmsg\xe1', field_name="contmsg", default_type="text/plain") self.assertEqual(info, u'contmsg\xe1') get_media_type.return_value = ["application/zip"] info = format_output(["1", "2"]) self.assertEqual(info, 'Unsupported Accept Media Types: application/zip')
def test_12_getradl(self): """ Test the GetInfrastructureRADL IM function """ (success, res) = self.server.GetInfrastructureRADL(self.inf_id, self.auth_data) self.assertTrue(success, msg="ERROR calling GetInfrastructureRADL: " + str(res)) try: radl_parse.parse_radl(res) except Exception as ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetInfrastructureRADL: " + str(ex))
def test_55_alter(self, checkResize, server_proxy): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m and disk.1.size=1GB and disk.1.device='hdc' and disk.1.fstype='ext4' and disk.1.mount_path='/mnt/disk' )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'one', 'type': 'OpenNebula', 'username': '******', 'password': '******', 'host': 'server.com:2633'}]) one_cloud = self.get_one_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", one_cloud.cloud, radl, radl, one_cloud) checkResize.return_value = True one_server = MagicMock() one_server.one.vm.action.return_value = (True, "", 0) one_server.one.vm.resize.return_value = (True, "", 0) one_server.one.vm.info.return_value = (True, read_file_as_string("files/vm_info_off.xml"), 0) one_server.one.vm.attach.return_value = (True, "", 0) server_proxy.return_value = one_server success, _ = one_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_30_updateVMInfo(self, connection): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'docker://someimage' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'docker', 'type': 'Docker', 'host': 'http://server.com:2375'}]) docker_cloud = self.get_docker_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", docker_cloud.cloud, radl, radl, docker_cloud) conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.getresponse.side_effect = self.get_response success, vm = docker_cloud.updateVMInfo(vm, auth) self.assertTrue(success, msg="ERROR: updating VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_10_concrete(self, get_driver): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'gce://us-central1-a/centos-6' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{'id': 'one', 'type': 'GCE', 'username': '******', 'password': '******', 'project': 'proj'}]) driver = MagicMock() get_driver.return_value = driver node_size = MagicMock() node_size.ram = 512 node_size.price = 1 node_size.disk = 1 node_size.name = "small" driver.list_sizes.return_value = [node_size] gce_cloud = self.get_gce_cloud() concrete = gce_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_10_concrete(self, get_driver): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'ost://server.com/ami-id' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{'id': 'ost', 'type': 'OpenStack', 'username': '******', 'password': '******', 'tenant': 'tenant', 'host': 'https://server.com:5000'}]) ost_cloud = self.get_ost_cloud() driver = MagicMock() get_driver.return_value = driver node_size = MagicMock() node_size.ram = 512 node_size.price = 1 node_size.disk = 1 node_size.vcpus = 1 node_size.name = "small" driver.list_sizes.return_value = [node_size] concrete = ost_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_altervm(self): """Test AlterVM""" radl = RADL() radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("cpu.count", "=", 1), Feature("memory.size", "=", 512, "M"), Feature("disk.0.os.credentials.password", "=", "pass")])) radl.add(deploy("s0", 1)) auth0 = self.getAuth([0], [], [("Dummy", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) radl = RADL() radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("cpu.count", "=", 2), Feature("memory.size", "=", 1024, "M"), Feature("disk.0.os.credentials.password", "=", "pass")])) radl.add(deploy("s0", 1)) radl_info = IM.AlterVM(infId, "0", str(radl), auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual(parsed_radl_info.systems[0].getValue("cpu.count"), 2) self.assertEqual(parsed_radl_info.systems[0].getFeature('memory.size').getValue('M'), 1024) IM.DestroyInfrastructure(infId, auth0)
def test_30_updateVMInfo(self, server_proxy): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'one', 'type': 'OpenNebula', 'username': '******', 'password': '******', 'host': 'server.com:2633'}]) one_cloud = self.get_one_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", one_cloud.cloud, radl, radl, one_cloud) one_server = MagicMock() one_server.one.vm.info.return_value = (True, read_file_as_string("files/vm_info.xml"), 0) server_proxy.return_value = one_server success, vm = one_cloud.updateVMInfo(vm, auth) self.assertTrue(success, msg="ERROR: updating VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def addresourcesform(infid=None): access_token = oidc_blueprint.session.token['access_token'] auth_data = utils.getUserAuthData(access_token, cred, session["userid"]) headers = {"Authorization": auth_data, "Accept": "text/plain"} url = "%s/infrastructures/%s/radl" % (settings.imUrl, infid) response = requests.get(url, headers=headers) if response.ok: systems = [] try: radl = radl_parse.parse_radl(response.text) systems = radl.systems except Exception as ex: flash("Error parsing RADL: \n%s" % str(ex), 'error') return render_template('addresource.html', infid=infid, systems=systems) else: flash("Error getting RADL: \n%s" % (response.text), 'error') return redirect(url_for('showinfrastructures'))
def test_20_launch(self, save_data, sleep, requests): radl_data = """ network net1 (outbound = 'yes' and outports = '8080,9000:9100') network net2 () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net1' and net_interface.0.dns_name = 'test' and net_interface.1.connection = 'net2' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' and disk.1.size=1GB and disk.1.device='hdb' and disk.1.mount_path='/mnt/path' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'azure', 'type': 'AzureClassic', 'subscription_id': 'user', 'public_key': 'public_key', 'private_key': 'private_key'}]) azure_cloud = self.get_azure_cloud() requests.side_effect = self.get_response res = azure_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth) success, _ = res[0] self.assertTrue(success, msg="ERROR: launching a VM.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_30_updateVMInfo(self, requests): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'docker://someimage' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'fogbow', 'type': 'Kubernetes', 'host': 'http://server.com:8080'}]) kube_cloud = self.get_kube_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 inf.id = "namespace" vm = VirtualMachine(inf, "1", kube_cloud.cloud, radl, radl, kube_cloud) requests.side_effect = self.get_response success, vm = kube_cloud.updateVMInfo(vm, auth) self.assertTrue(success, msg="ERROR: updating VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_altervm(self): """Test AlterVM""" radl = RADL() radl.add( system("s0", [ Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("cpu.count", "=", 1), Feature("memory.size", "=", 512, "M"), Feature("disk.0.os.credentials.password", "=", "pass") ])) radl.add(deploy("s0", 1)) auth0 = self.getAuth([0], [], [("Dummy", 0)]) infId = IM.CreateInfrastructure(str(radl), auth0) radl = RADL() radl.add( system("s0", [ Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"), Feature("disk.0.os.credentials.username", "=", "user"), Feature("cpu.count", "=", 2), Feature("memory.size", "=", 1024, "M"), Feature("disk.0.os.credentials.password", "=", "pass") ])) radl.add(deploy("s0", 1)) radl_info = IM.AlterVM(infId, "0", str(radl), auth0) parsed_radl_info = parse_radl(str(radl_info)) self.assertEqual(parsed_radl_info.systems[0].getValue("cpu.count"), 2) self.assertEqual( parsed_radl_info.systems[0].getFeature('memory.size').getValue( 'M'), 1024) IM.DestroyInfrastructure(infId, auth0)
def deserialize(str_data): dic = json.loads(str_data) if dic['cloud']: dic['cloud'] = IM.CloudInfo.CloudInfo.deserialize(dic['cloud']) if dic['info']: dic['info'] = parse_radl(dic['info']) if dic['requested_radl']: dic['requested_radl'] = parse_radl(dic['requested_radl']) newvm = VirtualMachine(None, None, None, None, None, None, dic['im_id']) newvm.__dict__.update(dic) # If we load a VM that is not configured, set it to False # because the configuration process will be lost if newvm.configured is None: newvm.configured = False return newvm
def test_10_concrete(self): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and #disks.free_size>=2g and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.flavour='ubuntu' and disk.0.os.version>='12.04' #disk.0.os.flavour='centos' and #disk.0.os.version>='6' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] for cloud_id, cloud in cloud_list.items(): if self.connectors_to_test == "all" or cloud_id in self.connectors_to_test: systems = self.concrete_systems_with_vmrc(radl_system) concrete_systems = [] for s in systems: concrete_systems.extend(cloud.concreteSystem(s, auth)) self.assertTrue( len(concrete_systems) > 0, msg= "ERROR: no system returned by concreteSystems for cloud: " + cloud_id)
def test_10_concrete(self, connection): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{'id': 'azure', 'type': 'Azure', 'username': '******', 'public_key': 'public_key', 'private_key': 'private_key'}]) azure_cloud = self.get_azure_cloud() conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.getresponse.side_effect = self.get_response concrete = azure_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_10_concrete(self): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{ 'id': 'one', 'type': 'OpenNebula', 'username': '******', 'password': '******', 'host': 'server.com:2633' }]) one_cloud = self.get_one_cloud() concrete = one_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def AlterVM(inf_id, vm_id, radl_data, auth): """ Get information about a virtual machine in an infrastructure. Args: - inf_id(str): infrastructure id. - vm_id(str): virtual machine id. - radl(str): RADL description. - auth(Authentication): parsed authentication tokens. Return: a str with the information about the VM """ auth = InfrastructureManager.check_auth_data(auth) InfrastructureManager.logger.info( "Modifying the VM: '" + str(vm_id) + "' from inf: " + str(inf_id)) vm = InfrastructureManager.get_vm_from_inf(inf_id, vm_id, auth) if not vm: InfrastructureManager.logger.info( "VM does not exist or Access Error") raise Exception("VM does not exist or Access Error") if isinstance(radl_data, RADL): radl = radl_data else: radl = radl_parse.parse_radl(radl_data) exception = None try: (success, alter_res) = vm.alter(radl, auth) except Exception, e: exception = e
def test_30_updateVMInfo(self, requests): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'azure', 'type': 'AzureClassic', 'subscription_id': 'user', 'public_key': 'public_key', 'private_key': 'private_key'}]) azure_cloud = self.get_azure_cloud() inf = MagicMock() vm = VirtualMachine(inf, "1", azure_cloud.cloud, radl, radl, azure_cloud, 1) requests.side_effect = self.get_response success, vm = azure_cloud.updateVMInfo(vm, auth) self.assertTrue(success, msg="ERROR: updating VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_10_concrete(self): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'docker://someimage' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{ 'id': 'fogbow', 'type': 'Kubernetes', 'host': 'http://server.com:8080' }]) kube_cloud = self.get_kube_cloud() concrete = kube_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def deserialize(str_data): newinf = InfrastructureInfo() dic = json.loads(str_data) vm_list = dic['vm_list'] vm_master_id = dic['vm_master'] dic['vm_master'] = None dic['vm_list'] = [] if dic['auth']: dic['auth'] = Authentication.deserialize(dic['auth']) if dic['radl']: dic['radl'] = parse_radl(dic['radl']) if 'extra_info' in dic and dic['extra_info'] and "TOSCA" in dic['extra_info']: try: dic['extra_info']['TOSCA'] = Tosca.deserialize(dic['extra_info']['TOSCA']) except: del dic['extra_info']['TOSCA'] InfrastructureInfo.logger.exception("Error deserializing TOSCA document") newinf.__dict__.update(dic) newinf.cloud_connector = None # Set the ConfManager object and the lock to the data loaded newinf.cm = None newinf.ctxt_tasks = PriorityQueue() newinf.conf_threads = [] for vm_data in vm_list: vm = VirtualMachine.deserialize(vm_data) vm.inf = newinf if vm.im_id == vm_master_id: newinf.vm_master = vm newinf.vm_list.append(vm) return newinf
def test_55_alter(self): radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" radl = radl_parse.parse_radl(radl_data) for vm in self.vm_list: cl = vm.cloud.getCloudConnector() (success, msg) = cl.alterVM(vm, radl, auth) self.assertTrue(success, msg="ERROR: updating VM for cloud: " + vm.cloud.id + ": " + str(msg)) # wait the VM to resize time.sleep(30) # get the updated vm (success, new_vm) = cl.updateVMInfo(vm, auth) new_cpu = new_vm.info.systems[0].getValue('cpu.count') new_memory = new_vm.info.systems[0].getFeature( 'memory.size').getValue('M') self.assertGreaterEqual(new_cpu, 2, msg="ERROR: updating VM for cloud: " + vm.cloud.id + ". CPU num must at least 2.") self.assertGreaterEqual(new_memory, 1024, msg="ERROR: updating VM for cloud: " + vm.cloud.id + ". Memory must be at least 1024M.")
def test_15_get_vm_info(self): """ Test the GetVMInfo IM function """ (success, vm_ids) = self.server.GetInfrastructureInfo( self.inf_id, self.auth_data) self.assertTrue( success, msg="ERROR calling GetInfrastructureInfo: " + str(vm_ids)) (success, info) = self.server.GetVMInfo( self.inf_id, vm_ids[0], self.auth_data) self.assertTrue(success, msg="ERROR calling GetVMInfo: " + str(info)) try: radl_parse.parse_radl(info) except Exception, ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetVMInfo: " + str(ex))
def test_10_concrete(self): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'vsp://vspherehost/image-id' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{ 'id': 'vsp', 'type': 'vSphere', 'host': 'https://vspherehost', 'username': '******', 'password': '******' }]) vsphere_cloud = self.get_vsphere_cloud() concrete = vsphere_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_10_concrete(self): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'fbw://fogbow-ubuntu' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{ 'id': 'fogbow', 'type': 'FogBow', 'proxy': 'user', 'host': 'server.com:8182' }]) fogbow_cloud = self.get_fogbow_cloud() concrete = fogbow_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_20_launch(self, requests): radl_data = """ network net1 (outbound = 'yes' and outports = '8080') network net2 () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net1' and net_interface.0.dns_name = 'test' and net_interface.1.connection = 'net2' and disk.0.os.name = 'linux' and disk.0.image.url = 'docker://someimage' and disk.0.os.credentials.username = '******' and disk.1.size=1GB and disk.1.device='hdb' and disk.1.mount_path='/mnt/path' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'fogbow', 'type': 'Kubernetes', 'host': 'http://server.com:8080'}]) kube_cloud = self.get_kube_cloud() requests.side_effect = self.get_response res = kube_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth) success, _ = res[0] self.assertTrue(success, msg="ERROR: launching a VM.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_concrete_appdb(self, get_site_url, get_site_id): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'appdb://CESNET-MetaCloud/egi.ubuntu.16.04?fedcloud.egi.eu' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{ 'id': 'occi', 'type': 'OCCI', 'proxy': 'proxy', 'host': 'https://carach5.ics.muni.cz:11443' }]) occi_cloud = self.get_occi_cloud() occi_cloud.cloud.server = "carach5.ics.muni.cz" get_site_url.return_value = "https://carach5.ics.muni.cz:11443" get_site_id.return_value = "siteid" concrete = occi_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_10_concrete(self, requests): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count>=1 and memory.size>=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{ 'id': 'azure', 'type': 'AzureClassic', 'subscription_id': 'user', 'public_key': 'public_key', 'private_key': 'private_key' }]) azure_cloud = self.get_azure_cloud() requests.side_effect = self.get_response concrete = azure_cloud.concreteSystem(radl_system, auth) self.assertEqual(len(concrete), 1) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_references(self): r = parse_radl(TESTS_PATH + "/test_radl_ref.radl") self.radl_check(r, [2, 2, 0, 2, 2]) radl_json = dump_radl_json(r) r = parse_radl_json(radl_json) self.radl_check(r, [2, 2, 0, 2, 2])
def test_55_alter(self, get_connection): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'ec2', 'type': 'EC2', 'username': '******', 'password': '******'}]) ec2_cloud = self.get_ec2_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "us-east-1;sid-1", ec2_cloud.cloud, radl, radl, ec2_cloud) conn = MagicMock() get_connection.return_value = conn reservation = MagicMock() instance = MagicMock() instance.update.return_value = True instance.stop.return_value = True instance.state = "stopped" reservation.instances = [instance] conn.get_all_instances.return_value = [reservation] success, _ = ec2_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_12_getradl(self): """ Test the GetInfrastructureRADL IM function """ before = time.time() (success, res) = self.server.GetInfrastructureRADL( self.inf_id, self.auth_data) resp_time = time.time() - before self.__class__.response_times.append(resp_time) self.assertTrue( success, msg="ERROR calling GetInfrastructureRADL: " + str(res)) try: radl_parse.parse_radl(res) except Exception, ex: self.assertTrue( False, msg="ERROR parsing the RADL returned by GetInfrastructureRADL: " + str(ex))
def test_55_alter(self, get_driver): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'libcloud', 'type': 'LibCloud', 'username': '******', 'password': '******', 'driver': 'EC2'}]) lib_cloud = self.get_lib_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", lib_cloud.cloud, radl, radl, lib_cloud) driver = MagicMock() get_driver.return_value = driver node = MagicMock() node.id = "1" node.driver = driver driver.list_nodes.return_value = [node] driver.ex_resize.return_value = True success, _ = lib_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_30_updateVMInfo(self, get_driver): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.ip = '158.42.1.1' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'aws://ami-id' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'libcloud', 'type': 'LibCloud', 'username': '******', 'password': '******', 'driver': 'EC2'}]) lib_cloud = self.get_lib_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", lib_cloud.cloud, radl, radl, lib_cloud) driver = MagicMock() driver.name = "Amazon EC2" get_driver.return_value = driver node = MagicMock() node.id = "1" node.state = "running" node.extra = {'availability': 'use-east-1'} node.public_ips = [] node.private_ips = ['10.0.0.1'] node.driver = driver node.size = MagicMock() node.size.ram = 512 node.size.price = 1 node.size.disk = 1 node.size.vcpus = 1 node.size.name = "small" driver.list_nodes.return_value = [node] volume = MagicMock() volume.id = "vol1" volume.extra = {"state": "available"} volume.attach.return_value = True driver.create_volume.return_value = volume driver.ex_allocate_address.return_value = "10.0.0.1" success, vm = lib_cloud.updateVMInfo(vm, auth) self.assertTrue(success, msg="ERROR: updating VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_55_alter(self, delete_proxy, get_keystone_uri, connection): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( disk.1.size=1GB and disk.1.device='hdc' and disk.1.fstype='ext4' and disk.1.mount_path='/mnt/disk' )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'occi', 'type': 'OCCI', 'proxy': 'proxy', 'host': 'https://server.com:11443'}]) occi_cloud = self.get_occi_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", occi_cloud.cloud, radl, radl, occi_cloud) conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.getresponse.side_effect = self.get_response get_keystone_uri.return_value = None success, _ = occi_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def radl_check(self, radl, expected_lengths=None, check_output=True): self.assertIsInstance(radl, RADL) radl.check() if expected_lengths: lengths = [len(l) for l in [radl.networks, radl.systems, radl.deploys, radl.configures, radl.contextualize]] self.assertEqual(lengths, expected_lengths) if check_output: self.radl_check(parse_radl(str(radl)), expected_lengths, check_output=False)
def test_check_newline(self): radl = """ system test ( auth = 'asd asd asd asd asd asd asd as dasd asd as das dasd as das d asd \n' and otra = 1 ) """ r = parse_radl(radl) r.check()
def _get_vms(self): now = cpyutils.eventloop.now() server = self._get_server() auth_data = self._read_auth_data(self._IM_VIRTUAL_CLUSTER_AUTH_DATA_FILE) (success, vm_ids) = server.GetInfrastructureInfo(self._get_inf_id(), auth_data) if not success: _LOGGER.error("ERROR getting infrastructure info: %s" % vm_ids) else: # The first one is always the front-end node for vm_id in vm_ids[1:]: clues_node_name = None try: (success, radl_data) = server.GetVMInfo(self._get_inf_id(), vm_id, auth_data) if success: radl = radl_parse.parse_radl(radl_data) clues_node_name = radl.systems[0].getValue('net_interface.0.dns_name') state = radl.systems[0].getValue('state') else: _LOGGER.error("ERROR getting VM info: %s" % vm_id) except TypeError: success = False reload(radl_parse) _LOGGER.exception("ERROR getting VM info: %s. Trying to reload radl_parse module." % vm_id) except: success = False _LOGGER.exception("ERROR getting VM info: %s" % vm_id) if clues_node_name: # Create or update VM info if clues_node_name not in self._mvs_seen: self._mvs_seen[clues_node_name] = self.VM_Node(vm_id, radl) else: if self._mvs_seen[clues_node_name].vm_id != vm_id: # this must not happen ... _LOGGER.warning("Node %s in VM with id %s now have a new ID: %s" % (clues_node_name, self._mvs_seen[clues_node_name].vm_id, vm_id)) self.power_off(clues_node_name) self._mvs_seen[clues_node_name].update(vm_id, radl) self._mvs_seen[clues_node_name].seen() if state in [VirtualMachine.FAILED, VirtualMachine.UNCONFIGURED]: # This VM is in "terminal" state remove it from the infrastructure _LOGGER.error("Node %s in VM with id %s is in state: %s" % (clues_node_name, vm_id, state)) self.recover(clues_node_name) elif state in [VirtualMachine.OFF, VirtualMachine.UNKNOWN]: # Do not terminate this VM, let's wait to lifecycle to check if it must be terminated _LOGGER.warning("Node %s in VM with id %s is in state: %s" % (clues_node_name, vm_id, state)) # from the nodes that we have powered on, check which of them are still running for nname, node in self._mvs_seen.items(): if (now - node.timestamp_seen) > self._IM_VIRTUAL_CLUSTER_FORGET_MISSING_VMS: _LOGGER.debug("vm %s is not seen for a while... let's forget it" % nname) del self._mvs_seen[nname] return self._mvs_seen
def test_20_launch(self, get_driver): radl_data = """ network net1 (outbound = 'yes') network net2 () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net1' and net_interface.0.dns_name = 'test' and net_interface.1.connection = 'net2' and disk.0.os.name = 'linux' and disk.0.image.url = 'aws://ami-id' and disk.0.os.credentials.username = '******' and disk.1.size=1GB and disk.1.device='hdb' and disk.1.mount_path='/mnt/path' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'libcloud', 'type': 'LibCloud', 'username': '******', 'password': '******', 'driver': 'EC2'}]) lib_cloud = self.get_lib_cloud() driver = MagicMock() driver.name = "Amazon EC2" driver.features = {"create_node": ["ssh_key"]} get_driver.return_value = driver node_size = MagicMock() node_size.ram = 512 node_size.price = 1 node_size.disk = 1 node_size.vcpus = 1 node_size.name = "small" driver.list_sizes.return_value = [node_size] driver.get_key_pair.return_value = "" keypair = MagicMock() keypair.public_key = "public" driver.create_key_pair.return_value = keypair driver.features = {'create_node': ['ssh_key']} node = MagicMock() node.id = "1" node.name = "name" driver.create_node.return_value = node res = lib_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth) success, _ = res[0] self.assertTrue(success, msg="ERROR: launching a VM.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_55_alter(self, connection): radl_data = """ network net () system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'one://server.com/1' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'fogbow', 'type': 'Kubernetes', 'host': 'http://server.com:8080'}]) kube_cloud = self.get_kube_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "namespace/1", kube_cloud.cloud, radl, radl, kube_cloud) conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.putrequest.side_effect = self.request conn.getresponse.side_effect = self.get_response success, _ = kube_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_55_alter(self, sleep, connection): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'azr://image-id' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) new_radl_data = """ system test ( cpu.count>=2 and memory.size>=2048m )""" new_radl = radl_parse.parse_radl(new_radl_data) auth = Authentication([{'id': 'azure', 'type': 'Azure', 'username': '******', 'public_key': 'public_key', 'private_key': 'private_key'}]) azure_cloud = self.get_azure_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", azure_cloud.cloud, radl, radl, azure_cloud) conn = MagicMock() connection.return_value = conn conn.request.side_effect = self.request conn.getresponse.side_effect = self.get_response success, _ = azure_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_30_updateVMInfo(self, get_driver): radl_data = """ network net (outbound = 'yes') system test ( cpu.arch='x86_64' and cpu.count=1 and memory.size=512m and net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and disk.0.image.url = 'gce://us-central1-a/centos-6' and disk.0.os.credentials.username = '******' and disk.1.size=1GB and disk.1.device='hdb' and disk.1.mount_path='/mnt/path' )""" radl = radl_parse.parse_radl(radl_data) radl.check() auth = Authentication([{'id': 'one', 'type': 'GCE', 'username': '******', 'password': '******', 'project': 'proj'}]) gce_cloud = self.get_gce_cloud() inf = MagicMock() inf.get_next_vm_id.return_value = 1 vm = VirtualMachine(inf, "1", gce_cloud.cloud, radl, radl, gce_cloud) driver = MagicMock() get_driver.return_value = driver node = MagicMock() zone = MagicMock() node.id = "1" node.state = "running" node.extra = {'flavorId': 'small'} node.public_ips = [] node.public_ips = ['158.42.1.1'] node.private_ips = ['10.0.0.1'] node.driver = driver zone.name = 'us-central1-a' node.extra = {'zone': zone} driver.ex_get_node.return_value = node volume = MagicMock() volume.id = "vol1" volume.attach.return_value = True volume.extra = {'status': 'READY'} driver.create_volume.return_value = volume success, vm = gce_cloud.updateVMInfo(vm, auth) self.assertTrue(success, msg="ERROR: updating VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_check_password(self): radl = """ network publica () system main ( disk.0.os.credentials.new.password = '******' ) """ r = parse_radl(radl) with self.assertRaises(RADLParseException): r.check() radl = """ network publica () system main ( disk.0.os.credentials.new.password = '******' ) """ r = parse_radl(radl) r.check()
def test_outports(self): radl = """ network publica (outbound = 'yes' and outports='8899a-8899,22-22') system main ( net_interface.0.connection = 'publica' ) """ r = parse_radl(radl) with self.assertRaises(RADLParseException): self.radl_check(r)