def setUpClass(cls): cls.server = xmlrpclib.ServerProxy( "http://" + HOSTNAME + ":" + str(TEST_PORT), allow_none=True) tests_path = os.path.dirname(os.path.realpath(__file__)) auth_file = tests_path + '/../auth.dat' cls.auth_data = Authentication.read_auth_data(auth_file) cls.inf_id = 0
def get_credentials(): if AUTH_FILE is None: logging.error("The authentication file is mandatory") auth_data = Authentication.read_auth_data(AUTH_FILE) if auth_data is None: logging.error("The authentication file has incorrect format.") return auth_data
def connect(): if AUTH_FILE is None: logging.error("The authentication file is mandatory") auth_data = Authentication.read_auth_data(AUTH_FILE) if auth_data is None: logging.error("The authentication file has incorrect format.") if XMLRCP_SSL: logging.debug("Client safely connecting with: " + IM_URL) from springpython.remoting.xmlrpc import SSLClient server = SSLClient(IM_URL, XMLRCP_SSL_CA_CERTS) else: logging.debug("Client connecting with: " + IM_URL) server = xmlrpclib.ServerProxy(IM_URL,allow_none=True) return auth_data, server
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_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() vm = VirtualMachine(inf, "1", one_cloud.cloud, radl, radl, one_cloud, 1) 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())
def test_50_start(self, requests): 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, "", "", docker_cloud) requests.side_effect = self.get_response success, _ = docker_cloud.start(vm, auth) self.assertTrue(success, msg="ERROR: stopping VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_52_reboot(self, get_connection): auth = Authentication([{'id': 'ec2', 'type': 'EC2', 'username': '******', 'password': '******'}]) ec2_cloud = self.get_ec2_cloud() inf = MagicMock() vm = VirtualMachine(inf, "us-east-1;id-1", ec2_cloud.cloud, "", "", ec2_cloud, 1) conn = MagicMock() get_connection.return_value = conn reservation = MagicMock() instance = MagicMock() instance.update.return_value = True instance.reboot.return_value = True reservation.instances = [instance] conn.get_all_instances.return_value = [reservation] success, _ = ec2_cloud.start(vm, auth) self.assertTrue(success, msg="ERROR: stopping VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_80_delete_image(self, sleep, get_connection): auth = Authentication([{ 'id': 'ec2', 'type': 'EC2', 'username': '******', 'password': '******' }]) ec2_cloud = self.get_ec2_cloud() conn = MagicMock() get_connection.return_value = conn conn.deregister_image.return_value = True success, msg = ec2_cloud.delete_image('aws://region/image-ami', auth) self.assertTrue(success, msg="ERROR: deleting image. %s" % msg) self.assertEqual(conn.deregister_image.call_args_list, [call('image-ami', delete_snapshot=True)]) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_10_concrete(self, credentials, compute_client): 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', 'subscription_id': 'subscription_id', 'username': '******', 'password': '******' }]) azure_cloud = self.get_azure_cloud() instace_type = MagicMock() instace_type.name = "instance_type1" instace_type.number_of_cores = 1 instace_type.memory_in_mb = 1024 instace_type.resource_disk_size_in_mb = 102400 instace_types = [instace_type] client = MagicMock() compute_client.return_value = client client.virtual_machine_sizes.list.return_value = instace_types 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_30_updateVMInfo(self, get_keystone_uri, 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 = 'https://server.com/666956cb-9d15-475e-9f19-a3732c82a327' and disk.0.os.credentials.username = '******' and disk.0.os.credentials.password = '******' )""" radl = radl_parse.parse_radl(radl_data) radl.check() 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) requests.side_effect = self.get_response get_keystone_uri.return_value = None success, vm = occi_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_60_finalize(self, requests): 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, "", "", kube_cloud) requests.side_effect = self.get_response success, _ = kube_cloud.finalize(vm, auth) self.assertTrue(success, msg="ERROR: finalizing VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_60_finalize(self, credentials, resource_client): auth = Authentication([{'id': 'azure', 'type': 'Azure', 'subscription_id': 'subscription_id', 'username': '******', 'password': '******'}]) azure_cloud = self.get_azure_cloud() radl_data = """ network net (outbound = 'yes') system test ( 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.domain.com' )""" radl = radl_parse.parse_radl(radl_data) inf = MagicMock() vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, radl, radl, azure_cloud, 1) success, _ = azure_cloud.finalize(vm, True, auth) self.assertTrue(success, msg="ERROR: finalizing 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())
def test_52_reboot(self, get_keystone_uri, requests): auth = Authentication([{ 'id': 'occi', 'type': 'OCCI', 'proxy': 'proxy', 'host': 'https://server.com:11443' }]) occi_cloud = self.get_occi_cloud() inf = MagicMock() vm = VirtualMachine(inf, "1", occi_cloud.cloud, "", "", occi_cloud, 1) requests.side_effect = self.get_response get_keystone_uri.return_value = None, None success, _ = occi_cloud.reboot(vm, auth) self.assertTrue(success, msg="ERROR: rebooting 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 = 'aws://us-east-one/ami-id' and disk.0.os.credentials.username = '******' )""" radl = radl_parse.parse_radl(radl_data) radl_system = radl.systems[0] auth = Authentication([{'id': 'ec2', 'type': 'EC2', 'username': '******', 'password': '******'}]) ec2_cloud = self.get_ec2_cloud() concrete = ec2_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_50_start(self, sleep, requests): 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, "", "", azure_cloud, 1) requests.side_effect = self.get_response success, _ = azure_cloud.start(vm, auth) self.assertTrue(success, msg="ERROR: stopping VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_60_finalize(self, requests): radl_data = """ network net (outbound = 'yes') system test ( cpu.count=1 and memory.size=512m )""" radl = radl_parse.parse_radl(radl_data) 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) requests.side_effect = self.get_response success, _ = docker_cloud.finalize(vm, auth) self.assertTrue(success, msg="ERROR: finalizing VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log() self.activate_swarm() success, _ = docker_cloud.finalize(vm, auth) self.activate_swarm(False) self.assertTrue(success, msg="ERROR: finalizing VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def test_20_launch(self, get_keystone_uri, 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 = 'http://server.com/666956cb-9d15-475e-9f19-a3732c82a327' 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': 'occi', 'type': 'OCCI', 'proxy': 'proxy', 'host': 'https://server.com:11443' }]) occi_cloud = self.get_occi_cloud() requests.side_effect = self.get_response get_keystone_uri.return_value = None res = occi_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_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_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()) self.clean_log()
def test_80_delete_image(self, sleep, getONEVersion, server_proxy): auth = Authentication([{ 'id': 'one', 'type': 'OpenNebula', 'username': '******', 'password': '******', 'host': 'server.com:2633' }]) one_cloud = self.get_one_cloud() getONEVersion.return_value = "4.12" one_server = MagicMock() one_server.one.image.delete.return_value = (True, "", 0) one_server.one.imagepool.info.return_value = ( True, "<IMAGE_POOL><IMAGE><ID>1</ID>" "<NAME>imagename</NAME></IMAGE></IMAGE_POOL>", 0) one_server.one.image.info.return_value = ( True, "<IMAGE><STATE>1</STATE></IMAGE>", 0) server_proxy.return_value = one_server success, msg = one_cloud.delete_image('one://server.com/1', auth) self.assertTrue(success, msg="ERROR: deleting image. %s" % msg) self.assertEqual(one_server.one.image.delete.call_args_list, [call('user:pass', 1)]) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) success, msg = one_cloud.delete_image('one://server.com/imagename', auth) self.assertTrue(success, msg="ERROR: deleting image. %s" % msg) self.assertEqual(one_server.one.image.delete.call_args_list[1], call('user:pass', 1)) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def test_20_launch(self, 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_55_alter(self, sleep, 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) 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': 'AzureClassic', 'subscription_id': 'user', '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) requests.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_50_start(self, server_proxy): 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, "", "", one_cloud, 1) one_server = MagicMock() one_server.one.vm.action.return_value = (True, "", 0) server_proxy.return_value = one_server success, _ = one_cloud.start(vm, auth) self.assertTrue(success, msg="ERROR: stopping VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
def deserialize_info(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_json(dic['radl']) newinf.__dict__.update(dic) newinf.cloud_connector = None # Set the ConfManager object and the lock to the data loaded newinf.cm = None newinf.conf_threads = [] for vm_data in vm_list: vm = DB150to151.deserialize_vm(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_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 test_50_start(self, get_driver): 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, "", "", lib_cloud, 1) driver = MagicMock() get_driver.return_value = driver node = MagicMock() node.id = "1" node.state = "running" node.driver = driver driver.list_nodes.return_value = [node] driver.ex_stop_node.return_value = True success, _ = lib_cloud.start(vm, auth) self.assertTrue(success, msg="ERROR: stopping VM info.") 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()) self.clean_log()
def test_55_alter(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 = '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 inf.id = "namespace" vm = VirtualMachine(inf, "1", kube_cloud.cloud, radl, radl, kube_cloud) requests.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())
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']) else: dic['radl'] = 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 Exception: 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) newinf.adding = False newinf.deleting = False return newinf
def test_70_create_snapshot(self, get_driver): 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, "", "", ost_cloud, 1) driver = MagicMock() driver.name = "OpenStack" get_driver.return_value = driver node = MagicMock() node.id = "1" node.driver = driver driver.ex_get_node_details.return_value = node image = MagicMock() image.id = "newimage" driver.create_image.return_value = image success, new_image = ost_cloud.create_snapshot(vm, 0, "image_name", True, auth) self.assertTrue(success, msg="ERROR: creating snapshot: %s" % new_image) self.assertEqual(new_image, "ost://server.com/newimage") self.assertEqual(driver.create_image.call_args_list, [call(node, "image_name")]) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
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_50_start(self, get_driver): 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, "", "", 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] driver.ex_start_node.return_value = True success, _ = ost_cloud.start(vm, auth) self.assertTrue(success, msg="ERROR: stopping VM info.") self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) self.clean_log()
def setUpClass(cls): cls.server = xmlrpclib.ServerProxy( "http://" + HOSTNAME + ":" + str(TEST_PORT), allow_none=True) cls.auth_data = Authentication.read_auth_data(AUTH_FILE) cls.inf_id = 0
import unittest, time import logging, logging.config from IM.CloudInfo import CloudInfo from IM.auth import Authentication from IM.radl import radl_parse from IM.VirtualMachine import VirtualMachine from IM.VMRC import VMRC from IM.InfrastructureInfo import InfrastructureInfo TESTS_PATH = '/home/micafer/codigo/git_im/im/test' AUTH_FILE = TESTS_PATH + '/auth.dat' auth = Authentication(Authentication.read_auth_data(AUTH_FILE)) cloud_list = dict([ (c.id, c.getCloudConnector()) for c in CloudInfo.get_cloud_list(auth) ]) class TestConnectors(unittest.TestCase): """ Class to test the IM connectors """ vm_list = [] """ List of VMs launched in the test """ #connectors_to_test = "all" connectors_to_test = ["kub"] """ Specify the connectors to test: "all": All the connectors specified in the auth file or a list with the IDs""" @classmethod