Example #1
0
    def test_20_launch(self, save_data, get_driver):
        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080,9000:9100' and sg_name= 'test')
            network net2 ()
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            instance_tags='key=value,key1=value2' and
            net_interface.0.connection = 'net1' and
            net_interface.1.connection = 'net2' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'cst://server.com/image-id' and
            disk.0.os.credentials.username = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        auth = Authentication([{
            'id': 'ost',
            'type': 'CloudStack',
            'username': '******',
            'password': '******',
            'host': 'http://server.com'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        osc_cloud = self.get_osc_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]

        driver.ex_create_security_group.return_value = {
            "name": "sgname",
            "id": "sgid"
        }
        driver.ex_list_security_groups.return_value = []
        driver.ex_create_security_group_rule.return_value = True

        driver.create_node.side_effect = self.create_node

        inf = InfrastructureInfo()
        inf.auth = auth
        res = osc_cloud.launch_with_retry(inf, radl, radl, 1, auth, 2, 1)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
Example #2
0
    def test_db(self, execute, select, table_exists, connect):

        table_exists.return_value = True
        select.return_value = [["1", "", read_file_as_string("../files/data.pkl")]]
        execute.return_value = True

        res = IM.get_data_from_db("mysql://*****:*****@server/db_name")
        self.assertEqual(len(res), 1)

        inf = InfrastructureInfo()
        inf.id = "1"
        success = IM.save_data_to_db("mysql://*****:*****@server/db_name", {"1": inf})
        self.assertTrue(success)
Example #3
0
    def test_20_launch(self, save_data, requests):
        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080')
            network net2 ()
            network net3 ()
            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
            net_interface.2.connection = 'net3' 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': 'docker',
            'type': 'Docker',
            'host': 'http://server.com:2375'
        }])
        docker_cloud = self.get_docker_cloud()

        requests.side_effect = self.get_response

        res = docker_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.activate_swarm()
        docker_cloud._swarm = None
        res = docker_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth)
        self.activate_swarm(False)
        docker_cloud._swarm = None
        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())
Example #4
0
    def test_20_launch(self, save_data, 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' and
            disk.2.image.url = 'http://server.com/storage/2'
            )"""
        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.return_error = True
        res = occi_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth)
        self.return_error = False
        success, msg = res[0]
        self.assertFalse(success)
        self.assertEqual(msg, "Error msg\n")
        self.assertEqual(self.call_count['DELETE']['/storage/1'], 1)
        self.assertNotIn('/storage/2', self.call_count['DELETE'])
Example #5
0
    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())
Example #6
0
    def test_20_launch(self, save_data, requests):
        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080,9000')
            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 = 'fbw://fogbow-ubuntu' 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': 'FogBow', 'token': 'user', 'host': 'server.com:8182'}])
        fogbow_cloud = self.get_fogbow_cloud()

        requests.side_effect = self.get_response

        res = fogbow_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())
Example #7
0
    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.ip = '10.0.0.1' and
            net_interface.0.dns_name = 'test' and
            net_interface.1.connection = 'net2' 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()

        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]

        driver.ex_get_image.return_value = "image"
        driver.ex_create_address.return_value = "ip"
        net = MagicMock()
        net.name = "default"
        driver.ex_list_networks.return_value = [net]

        node = MagicMock()
        node.id = "gce1"
        node.name = "gce1name"
        driver.create_node.return_value = node

        res = gce_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()
Example #8
0
 def test_tosca_get_outputs(self):
     """Test TOSCA get_outputs function"""
     tosca_data = read_file_as_string('../files/tosca_create.yml')
     tosca = Tosca(tosca_data)
     _, radl = tosca.to_radl()
     radl.systems[0].setValue("net_interface.0.ip", "158.42.1.1")
     radl.systems[0].setValue("disk.0.os.credentials.username", "ubuntu")
     radl.systems[0].setValue("disk.0.os.credentials.password", "pass")
     inf = InfrastructureInfo()
     vm = VirtualMachine(inf, "1", None, radl, radl, None)
     vm.requested_radl = radl
     inf.vm_list = [vm]
     outputs = tosca.get_outputs(inf)
     self.assertEqual(outputs, {'server_url': ['158.42.1.1'],
                                'server_creds': {'token_type': 'password',
                                                 'token': 'pass',
                                                 'user': '******'}})
Example #9
0
File: Azure.py Project: amcaar/im
    def test_20_launch(self, credentials, network_client, compute_client, storage_client, resource_client):
        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 = 'azr://Canonical/UbuntuServer/16.04.0-LTS/latest' 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': 'Azure', 'subscription_id': 'subscription_id',
                                'username': '******', 'password': '******'}])
        azure_cloud = self.get_azure_cloud()

        cclient = MagicMock()
        compute_client.return_value = cclient
        nclient = MagicMock()
        network_client.return_value = nclient

        subnet_create = MagicMock()
        subnet_create_res = MagicMock()
        subnet_create_res.id = "subnet-0"
        subnet_create.result.return_value = subnet_create_res
        nclient.subnets.create_or_update.return_value = subnet_create

        public_ip_create = MagicMock()
        public_ip_create_res = MagicMock()
        public_ip_create_res.id = "ip-0"
        public_ip_create.result.return_value = public_ip_create_res
        nclient.public_ip_addresses.create_or_update.return_value = public_ip_create

        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]
        cclient.virtual_machine_sizes.list.return_value = instace_types

        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())
        self.clean_log()
Example #10
0
    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())
Example #11
0
    def test_db(self):
        """ Test DB data access """
        inf = InfrastructureInfo()
        inf.id = "1"
        inf.auth = self.getAuth([0], [], [("Dummy", 0)])
        cloud = CloudInfo()
        cloud.type = "Dummy"
        radl = RADL()
        radl.add(
            system(
                "s0",
                [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er")]))
        radl.add(deploy("s0", 1))
        vm1 = VirtualMachine(inf, "1", cloud, radl, radl)
        vm2 = VirtualMachine(inf, "2", cloud, radl, radl)
        inf.vm_list = [vm1, vm2]
        inf.vm_master = vm1
        # first create the DB table
        Config.DATA_DB = "sqlite:///tmp/ind.dat"
        InfrastructureList.load_data()

        success = InfrastructureList._save_data_to_db(Config.DATA_DB,
                                                      {"1": inf})
        self.assertTrue(success)

        res = InfrastructureList._get_data_from_db(Config.DATA_DB)
        self.assertEqual(len(res), 1)
        self.assertEqual(len(res['1'].vm_list), 2)
        self.assertEqual(res['1'].vm_list[0], res['1'].vm_master)
        self.assertEqual(
            res['1'].vm_master.info.systems[0].getValue("disk.0.image.url"),
            "mock0://linux.for.ev.er")
        self.assertTrue(res['1'].auth.compare(inf.auth,
                                              "InfrastructureManager"))
Example #12
0
 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'])
     if 'extra_info' in dic and dic['extra_info'] and "TOSCA" in dic['extra_info']:
         dic['extra_info']['TOSCA'] = Tosca.deserialize(dic['extra_info']['TOSCA'])
     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
Example #13
0
    def test_inf_auth_with_token(self):
        im_auth = {"token": (self.gen_token())}
        im_auth['username'] = InfrastructureInfo.OPENID_USER_PREFIX + "micafer"
        im_auth['password'] = "******"
        # Check that a user/pass cred cannot access OpenID ones
        user_auth = Authentication([{
            'id': 'im',
            'type': 'InfrastructureManager',
            'username': im_auth['username'],
            'password': im_auth['password']
        }])

        with self.assertRaises(Exception) as ex:
            IM.check_auth_data(user_auth)
        self.assertEqual(
            str(ex.exception),
            "Invalid username used for the InfrastructureManager.")

        inf = InfrastructureInfo()
        inf.id = "1"
        inf.auth = user_auth
        res = inf.is_authorized(user_auth)
        self.assertEqual(res, False)

        user_auth = Authentication([{
            'id': 'im',
            'type': 'InfrastructureManager',
            'username': im_auth['username'],
            'password': im_auth['password'],
            'token': im_auth['token']
        }])
        res = inf.is_authorized(user_auth)
        self.assertEqual(res, True)
Example #14
0
File: Tosca.py Project: vigial/im
 def test_tosca_get_outputs(self):
     """Test TOSCA get_outputs function"""
     tosca_data = read_file_as_string('../files/tosca_create.yml')
     tosca = Tosca(tosca_data)
     _, radl = tosca.to_radl()
     radl1 = radl.clone()
     radl1.systems = [radl.get_system_by_name('web_server')]
     radl1.systems[0].setValue("net_interface.1.ip", "158.42.1.1")
     radl1.systems[0].setValue("disk.0.os.credentials.username", "ubuntu")
     radl1.systems[0].setValue("disk.0.os.credentials.password", "pass")
     inf = InfrastructureInfo()
     vm = VirtualMachine(inf, "1", None, radl1, radl1, None)
     vm.requested_radl = radl1
     inf.vm_list = [vm]
     outputs = tosca.get_outputs(inf)
     self.assertEqual(
         outputs, {
             'server_url': ['158.42.1.1'],
             'server_creds': {
                 'token_type': 'password',
                 'token': 'pass',
                 'user': '******'
             }
         })
Example #15
0
    def test_20_launch(self, getONEVersion, server_proxy):
        radl_data = """
            network net1 (provider_id = 'publica' and 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 = 'one://server.com/1' 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': 'OpenNebula',
            'username': '******',
            'password': '******',
            'host': 'server.com:2633'
        }])
        one_cloud = self.get_one_cloud()

        getONEVersion.return_value = "4.12"

        one_server = MagicMock()
        one_server.one.vm.allocate.return_value = (True, "1", 0)
        one_server.one.vnpool.info.return_value = (
            True, read_file_as_string("files/nets.xml"), 0)
        server_proxy.return_value = one_server

        res = one_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()
Example #16
0
    def test_20_launch(self, delete_proxy, get_keystone_uri, connection):
        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()

        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

        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()
Example #17
0
    def test_20_launch(self):
        radl_data = """
            network net (outbound='yes' and outports='8899/tcp,22/tcp-22/tcp')
            system test (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            #memory.size>=1024m 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' and
            disk.0.os.credentials.new.password = '******' and
            #disk.0.os.flavour='centos' and
            #disk.0.os.version>='6' 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()
        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)

                launch_radl = radl.clone()
                launch_radl.systems = [concrete_systems[0]]
                res = cloud.launch(InfrastructureInfo(), launch_radl,
                                   launch_radl, 1, auth)
                for success, vm in res:
                    self.assertTrue(success,
                                    msg="ERROR: launching a VM for cloud: " +
                                    cloud_id)
                    self.__class__.vm_list.append(vm)
Example #18
0
    def test_20_launch(self, connection):
        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()

        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

        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()
Example #19
0
    def test_20_launch(self, get_image_data, save_data, get_driver):
        radl_data = """
            network net1 (outbound = 'yes' and provider_id = 'public' and
                          outports = '8080,9000:9100' and sg_name= 'test')
            network net2 (dnsserver='1.1.1.1' and create = 'yes')
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            instance_tags='key=value,key1=value2' and
            net_interface.1.connection = 'net1' and
            net_interface.0.connection = 'net2' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'ost://server.com/ami-id' and
            disk.0.os.credentials.username = '******' and
            disk.1.size=1GB and
            disk.1.device='hdb' and
            disk.2.image.url = 'ost://server.com/vol-id' and
            disk.2.device='hdc'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        auth = Authentication([{
            'id': 'ost',
            'type': 'OpenStack',
            'username': '******',
            'password': '******',
            'tenant': 'tenant',
            'host': 'https://server.com:5000'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        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]

        net1 = MagicMock()
        net1.name = "public"
        net1.id = "net1id"
        net1.extra = {'router:external': True}
        net1.cidr = None
        net2 = MagicMock()
        net2.name = "private"
        net2.id = "net2id"
        net2.cidr = "10.0.0.0/24"
        driver.ex_list_networks.return_value = [net2, net1]

        sg = MagicMock()
        sg.name = "sg"
        driver.ex_create_security_group.return_value = sg
        driver.ex_list_security_groups.return_value = []
        driver.ex_create_security_group_rule.return_value = True

        driver.features = {'create_node': ['ssh_key']}

        driver.create_node.side_effect = self.create_node

        driver.ex_create_network.return_value = net2
        subnet1 = MagicMock()
        driver.ex_create_subnet.return_value = subnet1

        router = MagicMock()
        router.id = "id"
        router.name = "name"
        router.extra = {'external_gateway_info': {'network_id': net1.id}}
        driver.ex_list_routers.return_value = [router]
        driver.ex_add_router_subnet.return_value = True

        image = MagicMock()
        image.id = 'imageid'
        driver.get_image.return_value = image
        vol = MagicMock()
        vol.id = 'volid'
        driver.ex_get_volume.return_value = vol

        inf = InfrastructureInfo()
        inf.radl = radl
        inf.auth = auth
        res = ost_cloud.launch_with_retry(inf, radl, radl, 1, auth, 2, 1)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
        self.assertEqual(driver.create_node.call_args_list[0][1]['networks'],
                         [net1])
        mappings = [{
            'source_type': 'image',
            'uuid': 'imageid',
            'boot_index': 0,
            'delete_on_termination': False,
            'device_name': 'vda'
        }, {
            'guest_format': 'ext3',
            'boot_index': 1,
            'volume_size': 1,
            'device_name': 'vdb',
            'source_type': 'blank',
            'destination_type': 'volume',
            'delete_on_termination': True
        }, {
            'boot_index': 2,
            'delete_on_termination': False,
            'destination_type': 'volume',
            'device_name': 'vdc',
            'source_type': 'volume',
            'uuid': 'volid'
        }]
        self.assertEqual(
            driver.create_node.call_args_list[0][1]['ex_blockdevicemappings'],
            mappings)
        self.assertEqual(driver.ex_create_subnet.call_args_list[0][0][2],
                         "10.0.1.0/24")

        # test with proxy auth data
        auth = Authentication([{
            'id': 'ost',
            'type': 'OpenStack',
            'proxy': 'proxy',
            'tenant': 'tenant',
            'host': 'https://server.com:5000'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = ost_cloud.launch(inf, radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")

        get_image_data.return_value = "https://cloud.recas.ba.infn.it:5000", "image_id2", ""
        radl.systems[0].setValue(
            'disk.0.image.url',
            'appdb://CESNET-MetaCloud/egi.ubuntu.16.04?fedcloud.egi.eu')
        res = ost_cloud.launch(inf, radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
        self.assertEqual(driver.get_image.call_args_list[3][0][0], "image_id2")

        radl_data = """
            network net1 (outbound = 'yes')
            network net2 (create = 'yes')
            network net3 (create = 'yes')
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            instance_tags='key=value,key1=value2' and
            net_interface.1.connection = 'net1' and
            net_interface.0.connection = 'net2' and
            net_interface.2.connection = 'net3' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'ost://server.com/ami-id' and
            disk.0.os.credentials.username = '******' and
            disk.1.size=1GB and
            disk.1.device='hdb' and
            disk.2.image.url = 'ost://server.com/vol-id' and
            disk.2.device='hdc'
            )
            """
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = ost_cloud.launch(inf, radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
        self.assertEqual(driver.ex_create_subnet.call_args_list[5][0][2],
                         "10.0.2.0/24")
Example #20
0
    def test_20_launch(self, save_data, conn, pvim):
        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
            net_interface.1.ip = '10.0.0.2' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'vsp://vspherehost/vm-template' 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': 'vsp',
            'type': 'vSphere',
            'host': 'https://vspherehost',
            'username': '******',
            'password': '******'
        }])
        vsphere_cloud = self.get_vsphere_cloud()

        smatconn = MagicMock()
        conn.return_value = smatconn
        retcont = MagicMock()
        smatconn.RetrieveContent.return_value = retcont
        datacenter = MagicMock()
        retcont.rootFolder.childEntity = [datacenter]
        host = MagicMock()
        datacenter.hostFolder.childEntity = [host]
        retcont.viewManager.CreateContainerView.side_effect = self.CreateContainerView

        pvim.Datastore = vim.Datastore
        pvim.Network = vim.Network
        pvim.VirtualMachine = vim.VirtualMachine
        pvim.Task = vim.Task
        pvim.TaskInfo.State.success = vim.TaskInfo.State.success
        poolmgr = MagicMock()
        pvim.IpPoolManager.return_value = poolmgr
        ippool1 = MagicMock()
        ippool2 = MagicMock()
        poolmgr.QueryIpPools.return_value = [ippool1, ippool2]
        ippool1.name = "ippool1"
        ippool1.ipv4Config.subnetAddress = "10.0.0.1"
        ippool1.ipv4Config.netmask = "255.0.0.0"
        ippool2.name = "ippool2"
        ippool2.ipv4Config.subnetAddress = "8.8.8.8"
        ippool2.ipv4Config.netmask = "255.255.255.0"

        property_collector = MagicMock()
        smatconn.content.propertyCollector = property_collector
        update = MagicMock()
        property_collector.WaitForUpdates.return_value = update
        fs = MagicMock()
        update.filterSet = [fs]
        objs = MagicMock()
        fs.objectSet = [objs]
        change = MagicMock()
        objs.changeSet = [change]
        objs.obj = vim.Task("CreateVM")
        change.name = "info.state"
        change.val = vim.TaskInfo.State.success

        res = vsphere_cloud.launch_with_retry(InfrastructureInfo(), radl, radl,
                                              3, auth, 2, 0)
        self.assertEqual(len(res), 3)
        self.assertTrue(res[0][0])
        self.assertTrue(res[1][0])
        self.assertTrue(res[2][0])
Example #21
0
    def test_20_launch(self, get_driver):
        radl_data = """
            network net1 (outbound = 'yes' and provider_id = 'public' 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 = 'ost://server.com/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': '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]

        net = MagicMock()
        net.name = "public"
        driver.ex_list_networks.return_value = [net]

        sg = MagicMock()
        sg.name = "sg"
        driver.ex_create_security_group.return_value = sg
        driver.ex_list_security_groups.return_value = []
        driver.ex_create_security_group_rule.return_value = True

        keypair = MagicMock()
        keypair.public_key = "public"
        driver.create_key_pair.return_value = keypair
        driver.features = {'create_node': ['ssh_key']}

        node = MagicMock()
        node.id = "ost1"
        node.name = "ost1name"
        driver.create_node.return_value = node

        res = ost_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()
Example #22
0
    def test_20_launch(self, save_data, credentials, network_client, compute_client, storage_client, resource_client):
        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080,9000:9100' and sg_name = 'nsgname')
            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://Canonical/UbuntuServer/16.04.0-LTS/latest' 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': 'Azure', 'subscription_id': 'subscription_id',
                                'username': '******', 'password': '******'}])
        azure_cloud = self.get_azure_cloud()

        cclient = MagicMock()
        compute_client.return_value = cclient
        nclient = MagicMock()
        network_client.return_value = nclient
        rclient = MagicMock()
        resource_client.return_value = rclient

        nclient.virtual_networks.get.side_effect = Exception()

        subnet_create = MagicMock()
        subnet_create_res = MagicMock()
        subnet_create_res.id = "subnet-0"
        subnet_create.result.return_value = subnet_create_res
        nclient.subnets.create_or_update.return_value = subnet_create

        public_ip_create = MagicMock()
        public_ip_create_res = MagicMock()
        public_ip_create_res.id = "ip-0"
        public_ip_create.result.return_value = public_ip_create_res
        nclient.public_ip_addresses.create_or_update.return_value = public_ip_create

        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]
        cclient.virtual_machine_sizes.list.return_value = instace_types

        cclient.virtual_machines.create_or_update.side_effect = self.create_vm

        res = azure_cloud.launch_with_retry(InfrastructureInfo(), radl, radl, 3, auth, 2, 0)
        self.assertEqual(len(res), 3)
        self.assertTrue(res[0][0])
        self.assertTrue(res[1][0])
        self.assertTrue(res[2][0])
        self.assertEquals(rclient.resource_groups.delete.call_count, 2)
        self.assertIn("rg-userimage-", rclient.resource_groups.delete.call_args_list[0][0][0])
        self.assertIn("rg-userimage-", rclient.resource_groups.delete.call_args_list[1][0][0])
Example #23
0
    def test_20_launch(self, save_data, getONEVersion, server_proxy):
        radl_data = """
            network net1 (provider_id = 'publica' and outbound = 'yes' and
                          outports = '8080,9000:9100' and sg_name= 'test')
            network net2 ()
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            availability_zone='0' and
            net_interface.0.connection = 'net1' and
            net_interface.0.dns_name = 'test' and
            net_interface.1.connection = 'net2' and
            instance_tags = 'key=value,key1=value2' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'one://server.com/1' 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': 'OpenNebula',
            'username': '******',
            'password': '******',
            'host': 'server.com:2633'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        one_cloud = self.get_one_cloud()

        getONEVersion.return_value = "4.14.0"

        one_server = MagicMock()
        one_server.one.vm.allocate.return_value = (True, "1", 0)
        one_server.one.vnpool.info.return_value = (
            True, self.read_file_as_string("files/nets.xml"), 0)
        one_server.one.secgrouppool.info.return_value = (
            True, self.read_file_as_string("files/sgs.xml"), 0)
        one_server.one.secgroup.allocate.return_value = (True, 1, 0)
        server_proxy.return_value = one_server

        inf = InfrastructureInfo()
        inf.auth = auth
        res = one_cloud.launch(inf, radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
        sg_template = (
            'NAME = test\nRULE = [ PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 22:22 ]\n'
            'RULE = [ PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 8080:8080 ]\n'
            'RULE = [ PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 9000:9100 ]\n'
        )
        self.assertEqual(one_server.one.secgroup.allocate.call_args_list,
                         [call('user:pass', sg_template)])
        vm_template = """
            NAME = userimage

            CPU = 1
            VCPU = 1
            MEMORY = 512
            OS = [ ARCH = "x86_64" ]

            DISK = [ IMAGE_ID = "1" ]
 DISK = [ SAVE = no, TYPE = fs , FORMAT = ext3, SIZE = 1024, TARGET = hdb ]


            SCHED_REQUIREMENTS = "CLUSTER_ID=\\"0\\""\n"""
        self.assertIn(vm_template,
                      one_server.one.vm.allocate.call_args_list[0][0][1])
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())

        # Now test an error in allocate
        one_server.one.vm.allocate.return_value = (False, "Error msg", 0)
        res = one_cloud.launch(inf, radl, radl, 1, auth)
        success, msg = res[0]
        self.assertFalse(success)
        self.assertEqual(msg, "ERROR: Error msg")
Example #24
0
    def test_25_launch_spot(self, blockdevicemapping, VPCConnection,
                            get_region):
        radl_data = """
            network net1 (outbound = 'yes' and provider_id = 'vpc-id.subnet-id')
            network net2 ()
            system test (
            spot = 'yes' and
            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://us-east-one/ami-id' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.private_key = 'private' and
            disk.0.os.credentials.public_key = 'public' 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': 'ec2',
            'type': 'EC2',
            'username': '******',
            'password': '******'
        }])
        ec2_cloud = self.get_ec2_cloud()

        region = MagicMock()
        get_region.return_value = region

        conn = MagicMock()
        VPCConnection.return_value = conn

        image = MagicMock()
        device = MagicMock()
        reservation = MagicMock()
        instance = MagicMock()
        device.snapshot_id = True
        device.volume_id = True
        image.block_device_mapping = {"device": device}
        instance.add_tag.return_value = True
        instance.id = "iid"
        reservation.instances = [instance]
        image.run.return_value = reservation
        conn.get_image.return_value = image

        sg = MagicMock()
        sg.id = "sgid"
        sg.name = "sgname"
        sg.authorize.return_value = True
        conn.create_security_group.return_value = sg

        conn.get_all_security_groups.return_value = []

        blockdevicemapping.return_value = {'device': ''}

        zone = MagicMock()
        zone.name = 'us-east-1'
        conn.get_all_zones.return_value = [zone]
        history = MagicMock()
        history.price = 0.1
        conn.get_spot_price_history.return_value = [history]

        request = MagicMock()
        request.id = "id"
        conn.request_spot_instances.return_value = [request]

        res = ec2_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())
Example #25
0
File: Fogbow.py Project: vigial/im
    def test_20_launch(self, save_data, requests):
        radl_data = """
            network net1 (outbound = 'yes')
            network net2 (outports = '8080,9000/udp')
            network net3 (federated = 'yes' and providers = 'p1,p2')
            network net4 (federated = 'yes' and providers = ['p1','p2'])
            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
            net_interface.2.connection = 'net3' and
            net_interface.3.connection = 'net4' and
            availability_zone = 'cloud@site' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'fbw://server.com/fogbow-ubuntu' and
            disk.0.os.credentials.username = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        auth = Authentication([{
            'id': 'fogbow',
            'type': 'FogBow',
            'token': 'user',
            'host': 'server.com'
        }])
        fogbow_cloud = self.get_fogbow_cloud()

        requests.side_effect = self.get_response

        res = fogbow_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())

        data = json.loads(requests.call_args_list[2][1]["data"])
        self.assertEqual(data["allocationMode"], "dynamic")

        data = json.loads(requests.call_args_list[5][1]["data"])
        self.assertEqual(
            data, {
                "direction": "IN",
                "protocol": "TCP",
                "etherType": "IPv4",
                "portTo": 8080,
                "portFrom": 8080,
                "cidr": "0.0.0.0/0"
            })
        data = json.loads(requests.call_args_list[6][1]["data"])
        self.assertEqual(
            data, {
                "direction": "IN",
                "protocol": "UDP",
                "etherType": "IPv4",
                "portTo": 9000,
                "portFrom": 9000,
                "cidr": "0.0.0.0/0"
            })

        data = json.loads(requests.call_args_list[11][1]["data"])
        self.assertEqual(data["compute"]["cloudName"], "cloud")
        self.assertEqual(data["compute"]["provider"], "site")
        self.assertEqual(data["compute"]["vCPU"], 1)
        self.assertEqual(data["compute"]["memory"], 512)
        self.assertEqual(data["compute"]["imageId"], "fogbow-ubuntu")
        self.assertEqual(data["federatedNetworkId"], "1")
Example #26
0
    def test_20_launch(self, blockdevicemapping, VPCConnection, get_region):
        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 = 'aws://us-east-one/ami-id' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.private_key = 'private' and
            disk.0.os.credentials.public_key = 'public' 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': 'ec2',
            'type': 'EC2',
            'username': '******',
            'password': '******'
        }])
        ec2_cloud = self.get_ec2_cloud()

        region = MagicMock()
        get_region.return_value = region

        conn = MagicMock()
        VPCConnection.return_value = conn

        image = MagicMock()
        device = MagicMock()
        reservation = MagicMock()
        instance = MagicMock()
        device.snapshot_id = True
        device.volume_id = True
        image.block_device_mapping = {"device": device}
        instance.add_tag.return_value = True
        instance.id = "iid"
        reservation.instances = [instance]
        image.run.return_value = reservation
        conn.get_image.return_value = image

        subnet = MagicMock()
        subnet.id = "subnet-id"
        conn.get_all_subnets.return_value = [subnet]

        vpc = MagicMock()
        vpc.id = "vpc-id"
        conn.get_all_vpcs.return_value = [vpc]

        sg = MagicMock()
        sg.id = "sgid"
        sg.name = "sgname"
        sg.authorize.return_value = True
        conn.create_security_group.return_value = sg

        conn.get_all_security_groups.return_value = []

        blockdevicemapping.return_value = {'device': ''}

        res = ec2_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())

        # Check the case that we do not use VPC
        radl_data = """
            network net1 (outbound = 'yes' and outports='8080')
            network net2 ()
            system test (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=1g 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://us-east-one/ami-id' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.private_key = 'private' and
            disk.0.os.credentials.public_key = 'public' and
            disk.1.size=1GB and
            disk.1.device='hdb' and
            disk.1.mount_path='/mnt/path'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        conn.get_all_vpcs.return_value = []
        res = ec2_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
        # check the instance_type selected is correct
        self.assertEquals(image.run.call_args_list[1][1]["instance_type"],
                          "m1.small")

        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())
Example #27
0
    def test_20_launch(self, save_data, blockdevicemapping, VPCConnection, get_region):
        radl_data = """
            network net1 (outbound = 'yes' and outports='8080,9000:9100' and sg_name = 'sgname')
            network net2 ()
            system test (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            instance_tags = 'key=value,key1=value2' 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://us-east-one/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': 'ec2', 'type': 'EC2', 'username': '******', 'password': '******'},
                               {'type': 'InfrastructureManager', 'username': '******', 'password': '******'}])
        ec2_cloud = self.get_ec2_cloud()

        region = MagicMock()
        get_region.return_value = region

        conn = MagicMock()
        VPCConnection.return_value = conn

        image = MagicMock()
        device = MagicMock()
        reservation = MagicMock()
        instance = MagicMock()
        device.snapshot_id = True
        device.volume_id = True
        image.block_device_mapping = {"device": device}
        instance.add_tag.return_value = True
        instance.id = "iid"
        reservation.instances = [instance]
        conn.run_instances.return_value = reservation
        conn.get_image.return_value = image

        subnet = MagicMock()
        subnet.id = "subnet-id"
        conn.get_all_subnets.return_value = [subnet]

        vpc = MagicMock()
        vpc.id = "vpc-id"
        conn.get_all_vpcs.return_value = [vpc]

        sg = MagicMock()
        sg.id = "sgid"
        sg.name = "sgname"
        sg.authorize.return_value = True
        conn.create_security_group.return_value = sg

        conn.get_all_security_groups.return_value = []

        blockdevicemapping.return_value = {'device': ''}

        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = ec2_cloud.launch(inf, 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.assertEquals(len(conn.create_security_group.call_args_list), 3)
        self.assertEquals(conn.create_security_group.call_args_list[0][0][0], "im-%s" % inf.id)
        self.assertEquals(conn.create_security_group.call_args_list[1][0][0], "sgname")
        self.assertEquals(conn.create_security_group.call_args_list[2][0][0], "im-%s-net2" % inf.id)

        # Check the case that we do not use VPC
        radl_data = """
            network net1 (outbound = 'yes' and outports='8080')
            network net2 (create='yes' and cidr='10.0.128.0/24')
            network net3 (create='yes' and cidr='10.0.*.0/24')
            network net4 (create='yes')
            system test (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=1g 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://us-east-one/ami-id' and
            disk.0.os.credentials.username = '******' and
            #disk.0.os.credentials.private_key = 'private' and
            #disk.0.os.credentials.public_key = 'public' and
            disk.1.size=1GB and
            disk.1.device='hdb' and
            disk.1.mount_path='/mnt/path'
            )"""
        radl = radl_parse.parse_radl(radl_data)

        vpc = MagicMock()
        vpc.id = "vpc-id"
        conn.create_vpc.return_value = vpc
        conn.get_all_vpcs.side_effect = self._get_all_vpcs

        subnet = MagicMock()
        subnet.id = "subnet-id"
        subnet.cidr_block = "10.10.129.0/24"
        conn.create_subnet.return_value = subnet
        conn.get_all_subnets.side_effect = self.get_all_subnets

        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = ec2_cloud.launch(inf, radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
        # check the instance_type selected is correct
        self.assertEquals(conn.run_instances.call_args_list[1][1]["instance_type"], "t3a.micro")
        self.assertEquals(conn.create_vpc.call_args_list[0][0][0], "10.0.128.0/22")
        self.assertEquals(conn.create_subnet.call_args_list[0][0], ('vpc-id', '10.0.128.0/24'))
        self.assertEquals(conn.create_subnet.call_args_list[1][0], ('vpc-id', '10.0.129.0/24'))
        self.assertEquals(conn.create_subnet.call_args_list[2][0], ('vpc-id', '10.0.130.0/24'))

        self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
Example #28
0
    def test_20_launch(self, save_data, get_driver):
        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
            instance_tags='key=value,key1=value2' 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 = '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' and
            disk.2.image.url='gce://us-central1-a/somedisk' and
            disk.2.device='hdc' and
            disk.2.mount_path='/mnt2/path'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        auth = Authentication([{
            'id': 'one',
            'type': 'GCE',
            'username': '******',
            'password': '******',
            'project': 'proj'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        gce_cloud = self.get_gce_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"
        node_size.extra = {'guestCpus': 1}
        driver.list_sizes.return_value = [node_size]

        image = MagicMock()
        image.extra['selfLink'] = "image_selfLink"
        driver.ex_get_image.return_value = image
        driver.ex_create_address.return_value = "ip"
        net = MagicMock()
        net.name = "default"
        driver.ex_list_networks.return_value = [net]

        node = MagicMock()
        node.id = "gce1"
        node.name = "gce1name"
        driver.create_node.return_value = node

        node2 = MagicMock()
        node2.id = "gce2"
        node2.name = "gce2name"
        node3 = MagicMock()
        node3.id = "gce3"
        node3.name = "gce3name"
        driver.ex_create_multiple_nodes.return_value = [node, node2, node3]

        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = gce_cloud.launch(inf, radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a single VM.")
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())
        self.assertEqual(driver.create_node.call_args_list[0][1]['ex_network'],
                         "default")
        self.assertEqual(
            driver.create_node.call_args_list[0][1]['external_ip'],
            "ephemeral")
        self.assertEqual(
            driver.create_node.call_args_list[0][1]['ex_disks_gce_struct'][1]
            ['deviceName'], "hdb")
        self.assertEqual(
            driver.create_node.call_args_list[0][1]['ex_disks_gce_struct'][1]
            ['autoDelete'], True)
        self.assertEqual(
            driver.create_node.call_args_list[0][1]['ex_disks_gce_struct'][2]
            ['deviceName'], "hdc")
        self.assertEqual(
            driver.create_node.call_args_list[0][1]['ex_disks_gce_struct'][2]
            ['autoDelete'], False)
        self.assertEqual(driver.ex_create_firewall.call_args_list[0][0][0],
                         "im-%s-default-all" % inf.id)
        self.assertEqual(driver.ex_create_firewall.call_args_list[1][0][0],
                         "im-%s-default" % inf.id)
        self.assertEqual(driver.ex_create_firewall.call_args_list[0][0][1],
                         [{
                             'IPProtocol': 'udp',
                             'ports': '1-65535'
                         }, {
                             'IPProtocol': 'tcp',
                             'ports': '1-65535'
                         }, {
                             'IPProtocol': 'icmp'
                         }])
        self.assertEqual(driver.ex_create_firewall.call_args_list[1][0][1],
                         [{
                             'IPProtocol': 'tcp',
                             'ports': ['22', '8080', '9000-9100']
                         }])

        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = gce_cloud.launch(inf, radl, radl, 3, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching 3 VMs.")
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())

        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080,9000:9100')
            network net2 (create='yes' and cidr='10.0.*.0/24')
            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.0.ip = '10.0.0.1' and
            net_interface.1.connection = 'net2' 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()
        driver.create_node.side_effect = Exception("Error msg")

        net = MagicMock()
        net.cidr = "10.0.1.0/24"
        driver.ex_list_networks.return_value = [net]

        driver.ex_get_network.return_value = None
        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = gce_cloud.launch(inf, radl, radl, 1, auth)
        success, msg = res[0]
        self.assertFalse(success)
        self.assertEqual(msg, "ERROR: Error msg")
        self.assertEqual(driver.ex_destroy_address.call_count, 1)
        self.assertEqual(driver.ex_destroy_address.call_args_list,
                         [call('ip')])
        self.assertEqual(driver.ex_create_network.call_args_list[0][0][0],
                         "im-%s-net2" % inf.id)
        self.assertEqual(driver.ex_create_network.call_args_list[0][0][1],
                         "10.0.2.0/24")
Example #29
0
    def test_commands(self, bottle_request, check_auth_data,
                      get_infrastructure, SSH):
        """Test REST StopInfrastructure."""
        bottle_request.return_value = MagicMock()
        bottle_request.headers = {
            "AUTHORIZATION":
            ("type = InfrastructureManager; username = user; password = pass\n"
             "id = one; type = OpenNebula; host = onedock.i3m.upv.es:2633; "
             "username = user; password = pass")
        }
        bottle_request.environ = {'HTTP_HOST': 'imserver.com'}

        inf = InfrastructureInfo()
        inf.id = "1"
        inf.auth = Authentication([{
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        get_infrastructure.return_value = inf

        bottle_request.params = {'step': '1'}
        res = RESTGetVMProperty("1", "1", "command")
        auth_str = "Authorization: type = InfrastructureManager; username = user; password = pass"
        url = "http://imserver.com/infrastructures/1/vms/1/command?step=2"
        expected_res = """
                res="wait"
                while [ "$res" == "wait" ]
                do
                  res=`curl -s -H "%s" -H "Accept: text/plain" %s`
                  if [ "$res" != "wait" ]
                  then
                    eval "$res"
                  else
                    sleep 20
                  fi
                done""" % (auth_str, url)
        self.assertEqual(res, expected_res)

        radl_master = parse_radl("""
            network publica (outbound = 'yes')
            network privada ()

            system front (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            net_interface.0.ip = '8.8.8.8' and
            net_interface.0.connection = 'publica' and
            net_interface.1.connection = 'privada' and
            disk.0.image.url = 'mock0://linux.for.ev.er' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******' and
            disk.0.os.name = 'linux'
            )
        """)

        radl_vm1 = parse_radl("""
            network privada ()

            system wn (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            net_interface.0.connection = 'privada' and
            disk.0.image.url = 'mock0://linux.for.ev.er' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******' and
            disk.0.os.name = 'linux'
            )
        """)

        radl_vm2 = parse_radl("""
            network privada2 ()

            system wn2 (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            net_interface.0.connection = 'privada2' and
            disk.0.image.url = 'mock0://linux.for.ev.er' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******' and
            disk.0.os.name = 'linux'
            )
        """)

        # in the Master VM
        bottle_request.params = {'step': '2'}
        inf.vm_master = VirtualMachine(inf, None, None, radl_master,
                                       radl_master)
        inf.vm_master.creation_im_id = 0
        ssh = MagicMock()
        ssh.test_connectivity.return_value = True
        ssh.port = 22
        ssh.private_key = None
        ssh.password = "******"
        ssh.username = "******"
        ssh.host = "8.8.8.8"
        SSH.return_value = ssh
        vm1 = VirtualMachine(inf, None, None, radl_vm1, radl_vm1)
        vm1.creation_im_id = 1
        vm1.destroy = False
        vm2 = VirtualMachine(inf, None, None, radl_vm2, radl_vm2)
        vm2.creation_im_id = 2
        vm2.destroy = False
        inf.vm_list = [inf.vm_master, vm1, vm2]

        res = RESTGetVMProperty("1", "0", "command")
        expected_res = "true"
        self.assertEqual(res, expected_res)

        bottle_request.params = {'step': '2'}
        res = RESTGetVMProperty("1", "1", "command")
        expected_res = "true"
        self.assertEqual(res, expected_res)

        # in VM not connected to the Master VM
        res = RESTGetVMProperty("1", "2", "command")
        expected_res = (
            'sshpass -pyoyoyo ssh -N -R 20002:localhost:22 -p 22 -o "UserKnownHostsFile=/dev/null"'
            ' -o "StrictHostKeyChecking=no" [email protected] &')
        self.assertEqual(res, expected_res)
Example #30
0
    def test_20_launch(self, save_data, getONEVersion, server_proxy):
        radl_data = """
            network net1 (provider_id = 'publica' and outbound = 'yes' and
                          outports = '8080,9000:9100' and sg_name= 'test')
            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 = 'one://server.com/1' 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': 'OpenNebula',
            'username': '******',
            'password': '******',
            'host': 'server.com:2633'
        }])
        one_cloud = self.get_one_cloud()

        getONEVersion.return_value = "4.14.0"

        one_server = MagicMock()
        one_server.one.vm.allocate.return_value = (True, "1", 0)
        one_server.one.vnpool.info.return_value = (
            True, read_file_as_string("files/nets.xml"), 0)
        one_server.one.secgrouppool.info.return_value = (
            True, read_file_as_string("files/sgs.xml"), 0)
        one_server.one.secgroup.allocate.return_value = (True, 1, 0)
        server_proxy.return_value = one_server

        inf = InfrastructureInfo()
        res = one_cloud.launch(inf, radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a VM.")
        sg_template = (
            'NAME = test\nRULE = [ PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 22:22 ]\n'
            'RULE = [ PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 8080:8080 ]\n'
            'RULE = [ PROTOCOL = TCP, RULE_TYPE = inbound, RANGE = 9000:9100 ]\n'
        )
        self.assertEqual(one_server.one.secgroup.allocate.call_args_list,
                         [call('user:pass', sg_template)])
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())

        # Now test an error in allocate
        one_server.one.vm.allocate.return_value = (False, "Error msg", 0)
        res = one_cloud.launch(inf, radl, radl, 1, auth)
        success, msg = res[0]
        self.assertFalse(success)
        self.assertEqual(msg, "ERROR: Error msg")
Example #31
0
    def test_20_launch(self, save_data, get_driver):
        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080,9000:9100' and sg_name = 'fwname')
            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 = '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()

        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"
        node_size.extra = {'guestCpus': 1}
        driver.list_sizes.return_value = [node_size]

        driver.ex_get_image.return_value = "image"
        driver.ex_create_address.return_value = "ip"
        net = MagicMock()
        net.name = "default"
        driver.ex_list_networks.return_value = [net]

        node = MagicMock()
        node.id = "gce1"
        node.name = "gce1name"
        driver.create_node.return_value = node

        node2 = MagicMock()
        node2.id = "gce2"
        node2.name = "gce2name"
        node3 = MagicMock()
        node3.id = "gce3"
        node3.name = "gce3name"
        driver.ex_create_multiple_nodes.return_value = [node, node2, node3]

        res = gce_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching a single VM.")
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())

        res = gce_cloud.launch(InfrastructureInfo(), radl, radl, 3, auth)
        success, _ = res[0]
        self.assertTrue(success, msg="ERROR: launching 3 VMs.")
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())

        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080,9000:9100' and sg_name = 'fwname')
            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.0.ip = '10.0.0.1' and
            net_interface.1.connection = 'net2' 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()
        driver.create_node.side_effect = Exception("Error msg")
        res = gce_cloud.launch(InfrastructureInfo(), radl, radl, 1, auth)
        success, msg = res[0]
        self.assertFalse(success)
        self.assertEqual(msg, "ERROR: Error msg")
        self.assertEqual(driver.ex_destroy_address.call_count, 1)
        self.assertEqual(driver.ex_destroy_address.call_args_list,
                         [call('ip')])
Example #32
0
    def test_20_launch(self, save_data, credentials, network_client,
                       compute_client, storage_client, resource_client):
        radl_data = """
            network net1 (outbound = 'yes' and outports = '8080,9000:9100' and sg_name = 'nsgname')
            network net2 ()
            system test (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            instance_tags = 'key=value,key1=value2' 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://Canonical/UbuntuServer/16.04.0-LTS/latest' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******' and
            disk.1.size=1GB and
            disk.1.device='hdb' and
            disk.1.mount_path='/mnt/path' and
            disk.2.image.url='RGname/DiskName' and
            disk.2.device='hdb' and
            disk.2.mount_path='/mnt/path2'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        auth = Authentication([{
            'id': 'azure',
            'type': 'Azure',
            'subscription_id': 'subscription_id',
            'username': '******',
            'password': '******'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        azure_cloud = self.get_azure_cloud()

        cclient = MagicMock()
        compute_client.return_value = cclient
        nclient = MagicMock()
        network_client.return_value = nclient
        rclient = MagicMock()
        resource_client.return_value = rclient

        nclient.virtual_networks.get.side_effect = Exception()

        subnet_create = MagicMock()
        subnet_create_res = MagicMock()
        subnet_create_res.id = "subnet-0"
        subnet_create.result.return_value = subnet_create_res
        nclient.subnets.create_or_update.return_value = subnet_create

        public_ip_create = MagicMock()
        public_ip_create_res = MagicMock()
        public_ip_create_res.id = "ip-0"
        public_ip_create.result.return_value = public_ip_create_res
        nclient.public_ip_addresses.create_or_update.return_value = public_ip_create

        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]
        cclient.virtual_machine_sizes.list.return_value = instace_types

        cclient.virtual_machines.create_or_update.side_effect = self.create_vm

        disk = MagicMock()
        disk.name = "dname"
        disk.id = "did"
        cclient.disks.get.return_value = disk

        inf = InfrastructureInfo()
        inf.auth = auth
        inf.radl = radl
        res = azure_cloud.launch_with_retry(inf, radl, radl, 3, auth, 2, 0)
        self.assertEqual(len(res), 3)
        self.assertTrue(res[0][0])
        self.assertTrue(res[1][0])
        self.assertTrue(res[2][0])
        self.assertEquals(rclient.resource_groups.delete.call_count, 2)
        self.assertIn("rg-userimage-",
                      rclient.resource_groups.delete.call_args_list[0][0][0])
        self.assertIn("rg-userimage-",
                      rclient.resource_groups.delete.call_args_list[1][0][0])

        json_vm_req = cclient.virtual_machines.create_or_update.call_args_list[
            0][0][2]
        self.assertEquals(
            json_vm_req['storage_profile']['data_disks'][0]['disk_size_gb'], 1)
        self.assertEquals(
            json_vm_req['storage_profile']['data_disks'][1]['managed_disk']
            ['id'], "did")
        image_res = {
            'sku': '16.04.0-LTS',
            'publisher': 'Canonical',
            'version': 'latest',
            'offer': 'UbuntuServer'
        }
        self.assertEquals(json_vm_req['storage_profile']['image_reference'],
                          image_res)
        self.assertEquals(json_vm_req['hardware_profile']['vm_size'],
                          'instance_type1')
        self.assertEquals(json_vm_req['os_profile']['admin_username'], 'user')
        self.assertEquals(json_vm_req['os_profile']['admin_password'], 'pass')
        self.assertEquals(json_vm_req['os_profile']['admin_password'], 'pass')
        self.assertEquals(
            nclient.subnets.create_or_update.call_args_list[0][0][3],
            {'address_prefix': '10.0.1.0/24'})
        self.assertEquals(
            nclient.subnets.create_or_update.call_args_list[1][0][3],
            {'address_prefix': '10.0.2.0/24'})

        radl_data = """
            network net1 (outbound = 'yes')
            network net2 ()
            system test (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            instance_tags = 'key=value,key1=value2' 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://error/rgname/diskname' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()
        with self.assertRaises(Exception) as ex:
            azure_cloud.launch(inf, radl, radl, 1, auth)
        self.assertEquals(str(ex.exception),
                          "Incorrect image url: it must be snapshot or disk.")

        radl_data = """
            network net1 (outbound = 'yes')
            network net2 (cidr = '192.168.*.0/24')
            system test (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            instance_tags = 'key=value,key1=value2' 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://snapshot/rgname/diskname' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()
        res = azure_cloud.launch(inf, radl, radl, 1, auth)
        json_vm_req = cclient.virtual_machines.create_or_update.call_args_list[
            5][0][2]
        self.assertEquals(json_vm_req['storage_profile']['os_disk']['os_type'],
                          'linux')
        self.assertEquals(
            nclient.subnets.create_or_update.call_args_list[5][0][3],
            {'address_prefix': '192.168.1.0/24'})