Ejemplo n.º 1
0
    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()
        vm = VirtualMachine(inf, "1", occi_cloud.cloud, radl, radl, occi_cloud,
                            1)

        requests.side_effect = self.get_response

        get_keystone_uri.return_value = None, 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())

        memory = vm.info.systems[0].getValue("memory.size")
        self.assertEqual(memory, 1824522240)
Ejemplo n.º 2
0
    def test_30_updateVMInfo(self, server_proxy):
        radl_data = """
            network net ()
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            net_interface.0.connection = 'net' and
            net_interface.0.dns_name = 'test' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'one://server.com/1' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        auth = Authentication([{
            'id': 'one',
            'type': 'OpenNebula',
            'username': '******',
            'password': '******',
            'host': 'server.com:2633'
        }])
        one_cloud = self.get_one_cloud()

        inf = MagicMock()
        inf.get_next_vm_id.return_value = 1
        vm = VirtualMachine(inf, "1", one_cloud.cloud, radl, radl, one_cloud)

        one_server = MagicMock()
        one_server.one.vm.info.return_value = (
            True, read_file_as_string("files/vm_info.xml"), 0)
        server_proxy.return_value = one_server

        success, vm = one_cloud.updateVMInfo(vm, auth)

        self.assertTrue(success, msg="ERROR: updating VM info.")
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())
        self.clean_log()
Ejemplo n.º 3
0
    def test_52_reboot(self, conn, pvim):
        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
        retcont.viewManager.CreateContainerView.side_effect = self.CreateContainerView
        pvim.VirtualMachine = vim.VirtualMachine

        pvim.TaskInfo.State.success = vim.TaskInfo.State.success
        pvim.Task = vim.Task
        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("ResetVM")
        change.name = "info.state"
        change.val = vim.TaskInfo.State.success
        inf = MagicMock()
        vm = VirtualMachine(inf, "vm-template", vsphere_cloud.cloud, "", "",
                            vsphere_cloud, 1)

        success, _ = vsphere_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())
Ejemplo n.º 4
0
Archivo: GCE.py Proyecto: bbsyaya/im
    def test_60_finalize(self, sleep, get_driver):
        auth = Authentication([{
            'id': 'one',
            'type': 'GCE',
            'username': '******',
            'password': '******',
            'project': 'proj'
        }])
        gce_cloud = self.get_gce_cloud()

        radl_data = """
            system test (
            cpu.count>=2 and
            memory.size>=2048m
            )"""
        radl = radl_parse.parse_radl(radl_data)

        inf = MagicMock()
        vm = VirtualMachine(inf, "1", gce_cloud.cloud, radl, radl, gce_cloud,
                            1)

        driver = MagicMock()
        driver.name = "OpenStack"
        get_driver.return_value = driver

        node = MagicMock()
        node.destroy.return_value = True
        node.extra = {'disks': [{'source': 'vol'}]}
        node.driver = driver
        driver.ex_get_node.return_value = node

        volume = MagicMock()
        volume.detach.return_value = True
        volume.destroy.return_value = True
        driver.ex_get_volume.return_value = volume

        success, _ = gce_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())
Ejemplo n.º 5
0
    def test_30_updateVMInfo(self, connection):
        radl_data = """
            network net (outbound = 'yes')
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            net_interface.0.connection = 'net' and
            net_interface.0.dns_name = 'test' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'docker://someimage' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        radl.check()

        auth = Authentication([{
            'id': 'docker',
            'type': 'Docker',
            'host': 'http://server.com:2375'
        }])
        docker_cloud = self.get_docker_cloud()

        inf = MagicMock()
        inf.get_next_vm_id.return_value = 1
        vm = VirtualMachine(inf, "1", docker_cloud.cloud, radl, radl,
                            docker_cloud)

        conn = MagicMock()
        connection.return_value = conn

        conn.request.side_effect = self.request
        conn.getresponse.side_effect = self.get_response

        success, vm = docker_cloud.updateVMInfo(vm, auth)

        self.assertTrue(success, msg="ERROR: updating VM info.")
        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())
        self.clean_log()
Ejemplo n.º 6
0
    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.id = "namespace"
        vm = VirtualMachine(inf, "1", kube_cloud.cloud, "", "", kube_cloud, 1)

        requests.side_effect = self.get_response

        success, _ = kube_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())
Ejemplo n.º 7
0
Archivo: Docker.py Proyecto: bbsyaya/im
    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()
        vm = VirtualMachine(inf, "1", docker_cloud.cloud, "", "", docker_cloud,
                            1)

        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())
Ejemplo n.º 8
0
    def launch(self, inf, radl, requested_radl, num_vm, auth_data):
        res = []
        for _ in range(num_vm):
            now = str(int(time.time() * 100))
            vm = VirtualMachine(inf, now, self.cloud, requested_radl,
                                requested_radl)
            inf.add_vm(vm)

            vm.info.systems[0].setValue('provider.type', self.type)
            vm.state = VirtualMachine.RUNNING

            vm.info.systems[0].setValue("net_interface.0.ip", "10.0.0.1")
            vm.info.systems[0].setValue("disk.0.os.credentials.username",
                                        "username")
            vm.info.systems[0].setValue("disk.0.os.credentials.password",
                                        "password")

            res.append((True, vm))

        return res
Ejemplo n.º 9
0
    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()

        inf = MagicMock()
        vm = VirtualMachine(inf, "rg0/vm0", azure_cloud.cloud, "", "",
                            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())
Ejemplo n.º 10
0
    def test_get_ctxt_output(self, mkdtemp, get_ssh_ansible_master):
        ssh = MagicMock()
        get_ssh_ansible_master.return_value = ssh
        mkdtemp.return_value = "/tmp/test_get_ctxt"
        os.mkdir("/tmp/test_get_ctxt")
        with open('/tmp/test_get_ctxt/ctxt_agent.out', 'w+') as f:
            f.write('{"OK": true, "CHANGE_CREDS": true}')

        radl_data = """
            system test (
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******' and
            disk.0.os.credentials.new.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        inf = MagicMock()
        inf.id = "1"
        vm = VirtualMachine(inf, "1", None, radl, radl)
        cont_out = vm.get_ctxt_output("", delete=True)
        self.assertEqual(cont_out, "Contextualization agent output processed successfully")
        self.assertEqual(vm.info.systems[0].getCredentialValues(), ('user', 'newpass', None, None))
Ejemplo n.º 11
0
    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())
Ejemplo n.º 12
0
    def launch(self, inf, radl, requested_radl, num_vm, auth_data):
        server = ServerProxy(self.server_url, allow_none=True)
        session_id = self.getSessionID(auth_data)
        if session_id is None:
            return [(
                False,
                "Incorrect auth data, username and password must be specified for OpenNebula provider."
            )]

        sgs = self.create_security_groups(inf, radl, auth_data)

        system = radl.systems[0]
        # Currently ONE plugin prioritizes user-password credentials
        if system.getValue('disk.0.os.credentials.password'):
            system.delValue('disk.0.os.credentials.private_key')
            system.delValue('disk.0.os.credentials.public_key')

        res = []
        i = 0
        while i < num_vm:
            vm = VirtualMachine(inf, None, self.cloud, radl, requested_radl,
                                self)
            vm.destroy = True
            inf.add_vm(vm)
            template = self.getONETemplate(vm.info, sgs, auth_data, vm)

            self.log_debug("ONE Template: %s" % template)

            success, res_id = server.one.vm.allocate(session_id, template)[0:2]

            if success:
                vm.id = str(res_id)
                vm.info.systems[0].setValue('instance_id', str(res_id))
                vm.destroy = False
                res.append((success, vm))
            else:
                res.append((success, "ERROR: " + str(res_id)))
            i += 1

        return res
Ejemplo n.º 13
0
Archivo: Docker.py Proyecto: amcaar/im
    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()
Ejemplo n.º 14
0
    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())
Ejemplo n.º 15
0
    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())
Ejemplo n.º 16
0
    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())
Ejemplo n.º 17
0
    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()
Ejemplo n.º 18
0
    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())
Ejemplo n.º 19
0
    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())
Ejemplo n.º 20
0
    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())
Ejemplo n.º 21
0
    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())
Ejemplo n.º 22
0
    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())
Ejemplo n.º 23
0
    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.id = "namespace"
        vm = VirtualMachine(inf, "1", kube_cloud.cloud, radl, radl, kube_cloud,
                            1)

        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())
Ejemplo n.º 24
0
    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()
Ejemplo n.º 25
0
    def test_70_create_snapshot(self, sleep, get_connection):
        auth = Authentication([{'id': 'ec2', 'type': 'EC2', 'username': '******', 'password': '******'}])
        ec2_cloud = self.get_ec2_cloud()

        inf = MagicMock()
        vm = VirtualMachine(inf, "region;id1", ec2_cloud.cloud, "", "", ec2_cloud, 1)

        conn = MagicMock()
        get_connection.return_value = conn

        reservation = MagicMock()
        instance = MagicMock()
        instance.create_image.return_value = "image-ami"
        reservation.instances = [instance]
        conn.get_all_instances.return_value = [reservation]

        success, new_image = ec2_cloud.create_snapshot(vm, 0, "image_name", True, auth)

        self.assertTrue(success, msg="ERROR: creating snapshot: %s" % new_image)
        self.assertEqual(new_image, "aws://region/image-ami")
        self.assertEqual(instance.create_image.call_args_list, [call('image_name',
                                                                     description='AMI automatically generated by IM',
                                                                     no_reboot=True)])
        self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue())
Ejemplo n.º 26
0
Archivo: Tosca.py Proyecto: 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': '******'
             }
         })
Ejemplo n.º 27
0
    def launch(self, inf, radl, requested_radl, num_vm, auth_data):
        server = ServerProxy(self.server_url, allow_none=True)
        session_id = self.getSessionID(auth_data)
        if session_id is None:
            return [(
                False,
                "Incorrect auth data, username and password must be specified for OpenNebula provider."
            )]

        system = radl.systems[0]
        # Currently ONE plugin prioritizes user-password credentials
        if system.getValue('disk.0.os.credentials.password'):
            system.delValue('disk.0.os.credentials.private_key')
            system.delValue('disk.0.os.credentials.public_key')

        template = self.getONETemplate(radl, auth_data)
        res = []
        i = 0
        while i < num_vm:
            func_res = server.one.vm.allocate(session_id, template)
            if len(func_res) == 2:
                (success, res_id) = func_res
            elif len(func_res) == 3:
                (success, res_id, _) = func_res
            else:
                return [(False, "Error in the one.vm.allocate return value")]

            if success:
                vm = VirtualMachine(inf, str(res_id), self.cloud, radl,
                                    requested_radl, self)
                vm.info.systems[0].setValue('instance_id', str(res_id))
                res.append((success, vm))
            else:
                res.append((success, "ERROR: " + str(res_id)))
            i += 1
        return res
Ejemplo n.º 28
0
    def launch(self, inf, radl, requested_radl, num_vm, auth_data):
        service_name = None
        region = self.DEFAULT_LOCATION
        if radl.systems[0].getValue('availability_zone'):
            region = radl.systems[0].getValue('availability_zone')
        else:
            radl.systems[0].setValue('availability_zone', region)

        res = []
        i = 0
        while i < num_vm:
            try:
                subscription_id = self.get_subscription_id(auth_data)

                # Create storage account
                storage_account_name = self.get_storage_name(
                    subscription_id, region)
                storage_account = self.get_storage_account(
                    storage_account_name, auth_data)
                if not storage_account:
                    storage_account_name, error_msg = self.create_storage_account(
                        storage_account_name, auth_data, region)
                    if not storage_account_name:
                        res.append((False, error_msg))
                        break
                else:
                    # if the user has specified the region
                    if radl.systems[0].getValue('availability_zone'):
                        # Check that the region of the storage account is the
                        # same of the service
                        if region != storage_account.GeoPrimaryRegion:
                            res.append(
                                (False,
                                 ("Error creating the service. The specified "
                                  "region is not the same of the service.")))
                            break
                    else:
                        # Otherwise use the storage account region
                        region = storage_account.GeoPrimaryRegion

                # and the service
                service_name, error_msg = self.create_service(
                    auth_data, region)
                if service_name is None:
                    res.append((False, error_msg))
                    break

                self.log_info("Creating the VM with id: " + service_name)

                # Create the VM to get the nodename
                vm = VirtualMachine(inf, service_name, self.cloud, radl,
                                    requested_radl, self)
                vm.destroy = True
                inf.add_vm(vm)
                vm.info.systems[0].setValue('instance_id', str(vm.id))

                # Generate the XML to create the VM
                vm_create_xml = self.get_azure_vm_create_xml(
                    vm, storage_account_name, radl, i, auth_data)

                if vm_create_xml is None:
                    self.delete_service(service_name, auth_data)
                    res.append((False, "Incorrect image or auth data"))
                    break

                uri = "/services/hostedservices/%s/deployments" % service_name
                headers = {
                    'x-ms-version': '2013-03-01',
                    'Content-Type': 'application/xml'
                }
                resp = self.create_request('POST', uri, auth_data, headers,
                                           vm_create_xml)

                if resp.status_code != 202:
                    self.delete_service(service_name, auth_data)
                    self.log_error("Error creating the VM: Error Code " +
                                   str(resp.status_code) + ". Msg: " +
                                   resp.text)
                    res.append((False, "Error creating the VM: Error Code " +
                                str(resp.status_code) + ". Msg: " + resp.text))
                else:
                    vm.destroy = False
                    # Call the GET OPERATION STATUS until sea 200 (OK)
                    request_id = resp.headers['x-ms-request-id']
                    success = self.wait_operation_status(request_id, auth_data)
                    if success:
                        res.append((True, vm))
                    else:
                        self.log_exception("Error waiting the VM creation")
                        self.delete_service(service_name, auth_data)
                        res.append((False, "Error waiting the VM creation"))

            except Exception as ex:
                self.log_exception("Error creating the VM")
                if service_name:
                    self.delete_service(service_name, auth_data)
                res.append((False, "Error creating the VM: " + str(ex)))

            i += 1
        return res
Ejemplo n.º 29
0
    def test_60_finalize(self, sleep, get_driver):
        auth = Authentication([{
            'id': 'ost',
            'type': 'OpenStack',
            'username': '******',
            'password': '******',
            'tenant': 'tenant',
            'host': 'https://server.com:5000'
        }])
        ost_cloud = self.get_ost_cloud()

        radl_data = """
            network public (outboud = 'yes')
            network private (create = 'yes' and provider_id = ' im-infid-private')
            system test (
            cpu.count>=2 and
            memory.size>=2048m and
            net_interface.0.connection = 'public' and
            net_interface.1.connection = 'private'
            )"""
        radl = radl_parse.parse_radl(radl_data)

        inf = MagicMock()
        inf.id = "infid"
        inf.radl = radl
        vm = VirtualMachine(inf, "1", ost_cloud.cloud, radl, radl, ost_cloud,
                            1)

        driver = MagicMock()
        driver.name = "OpenStack"
        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
        node.destroy.return_value = True
        driver.ex_get_node_details.return_value = node

        driver.delete_security_group.return_value = True

        fip = MagicMock()
        fip.node_id = node.id
        fip.ip_address = '158.42.1.1'
        fip.delete.return_value = True
        driver.ex_list_floating_ips.return_value = [fip]
        driver.ex_detach_floating_ip_from_node.return_value = True

        sg1 = MagicMock()
        sg1.name = "im-infid-private"
        sg1.description = "Security group created by the IM"
        sg2 = MagicMock()
        sg2.name = "im-infid-public"
        sg2.description = "Security group created by the IM"
        sg3 = MagicMock()
        sg3.name = "im-infid"
        sg3.description = ""
        driver.ex_list_security_groups.return_value = [sg1, sg2, sg3]

        net1 = MagicMock()
        net1.name = "im-infid-private"
        net1.cidr = None
        net1.extra = {'subnets': ["subnet1"]}
        net2 = MagicMock()
        net2.name = "public"
        net2.cidr = None
        net2.extra = {'subnets': [], 'router:external': True}
        driver.ex_list_networks.return_value = [net1, net2]

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

        volume = MagicMock()
        driver.ex_get_volume.return_value = volume
        driver.detach_volume.return_value = True
        driver.ex_remove_security_group_from_node.return_value = True

        vm.volumes = ['volid']
        success, _ = ost_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())

        self.assertEqual(node.destroy.call_args_list, [call()])
        self.assertEqual(driver.detach_volume.call_args_list[0][0][0], volume)
        self.assertEqual(
            driver.ex_remove_security_group_from_node.call_args_list[0][0]
            [0].name, "im-infid")
        self.assertEqual(
            driver.ex_remove_security_group_from_node.call_args_list[1][0]
            [0].name, "im-infid-public")
        self.assertEqual(
            driver.ex_remove_security_group_from_node.call_args_list[2][0]
            [0].name, "im-infid-private")
        self.assertEqual(driver.ex_del_router_subnet.call_args_list[0][0][0],
                         router)
        self.assertEqual(
            driver.ex_del_router_subnet.call_args_list[0][0][1].id, "subnet1")
        self.assertEqual(driver.ex_delete_network.call_args_list[0][0][0],
                         net1)
        self.assertEqual(
            driver.ex_delete_security_group.call_args_list[0][0][0], sg2)
        self.assertEqual(
            driver.ex_delete_security_group.call_args_list[1][0][0], sg1)
        self.assertEqual(fip.delete.call_args_list, [call()])
        self.assertEqual(
            driver.ex_detach_floating_ip_from_node.call_args_list[0][0],
            (node, fip))

        vm.floating_ips = ['158.42.1.1']
        success, _ = ost_cloud.finalize(vm, True, auth)
        self.assertEqual(fip.delete.call_args_list, [call()])
        self.assertEqual(node.destroy.call_args_list, [call(), call()])
Ejemplo n.º 30
0
    def test_55_alter(self, add_elastic_ip_from_pool, get_driver):
        radl_data = """
            network net ()
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            net_interface.0.connection = 'net' and
            net_interface.0.dns_name = 'test' and
            disk.0.os.name = 'linux' and
            disk.0.image.url = 'one://server.com/1' and
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)

        new_radl_data = """
            system test (
            cpu.count>=2 and
            memory.size>=2048m
            )"""
        new_radl = radl_parse.parse_radl(new_radl_data)

        auth = Authentication([{
            'id': 'ost',
            'type': 'OpenStack',
            'username': '******',
            'password': '******',
            'tenant': 'tenant',
            'host': 'https://server.com:5000'
        }])
        ost_cloud = self.get_ost_cloud()

        inf = MagicMock()
        vm = VirtualMachine(inf, "1", ost_cloud.cloud, radl, radl, ost_cloud,
                            1)
        vm.volumes = []

        driver = MagicMock()
        get_driver.return_value = driver

        node = MagicMock()
        node.id = "1"
        node.state = "running"
        node.extra = {'flavorId': 'small', 'vm_state': 'resized'}
        node.public_ips = []
        node.private_ips = ['10.0.0.1']
        node.driver = driver
        driver.ex_get_node_details.return_value = node

        node_size = MagicMock()
        node_size.ram = 2048
        node_size.price = 1
        node_size.disk = 1
        node_size.vcpus = 2
        node_size.name = "small"
        driver.list_sizes.return_value = [node_size]
        driver.ex_get_size.return_value = node_size

        driver.ex_resize.return_value = True
        driver.ex_confirm_resize.return_value = True

        success, _ = ost_cloud.alterVM(vm, new_radl, auth)

        self.assertTrue(success, msg="ERROR: modifying VM info.")
        self.assertEqual(driver.ex_resize.call_args_list[0][0],
                         (node, node_size))
        self.assertEqual(driver.ex_confirm_resize.call_args_list[0][0],
                         (node, ))

        new_radl_data = """
            system test (
            disk.1.size = 10G
            )"""
        new_radl = radl_parse.parse_radl(new_radl_data)

        volume = MagicMock()
        volume.id = 'volid'
        volume.extra = {'state': 'available'}
        volume.attach.return_value = True
        volumeused = MagicMock()
        volumeused.extra = {
            'state': 'in-use',
            'attachments': [{
                'device': 'hdc'
            }]
        }
        volumeused.id = 'volid'
        volume.driver.ex_get_volume.return_value = volumeused
        driver.create_volume.return_value = volume

        success, _ = ost_cloud.alterVM(vm, new_radl, auth)
        self.assertEqual(vm.info.systems[0].getValue("disk.1.device"), 'hdc')
        self.assertTrue(success, msg="ERROR: modifying VM info.")

        new_radl_data = """
            network net1 (outbound = 'yes' and provider_id = 'pool1')
            system test (
            net_interface.0.connection = 'net1'
            )"""
        new_radl = radl_parse.parse_radl(new_radl_data)

        add_elastic_ip_from_pool.return_value = True, ""

        success, _ = ost_cloud.alterVM(vm, new_radl, auth)
        self.assertTrue(success, msg="ERROR: modifying VM info.")
        self.assertEqual(add_elastic_ip_from_pool.call_args_list[0][0],
                         (vm, node, None, 'pool1'))

        radl_data = """
            network net (outbound = 'yes' and provider_id = 'pool1')
            system test (
            cpu.arch='x86_64' and
            cpu.count=1 and
            memory.size=512m and
            net_interface.0.connection = 'net' and
            net_interface.0.ip = '8.8.8.8' 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)
        vm = VirtualMachine(inf, "1", ost_cloud.cloud, radl, radl, ost_cloud,
                            1)

        new_radl_data = """
            network net ()
            system test (
            net_interface.0.connection = 'net'
            )"""
        new_radl = radl_parse.parse_radl(new_radl_data)

        fip = MagicMock()
        fip.delete.return_value = True
        driver.ex_get_floating_ip.return_value = fip
        driver.ex_detach_floating_ip_from_node.return_value = True
        node.public_ips = ['158.42.1.1']

        success, _ = ost_cloud.alterVM(vm, new_radl, auth)
        self.assertTrue(success, msg="ERROR: modifying VM info.")
        self.assertEqual(
            driver.ex_detach_floating_ip_from_node.call_args_list[0][0],
            (node, fip))
        self.assertIsNone(
            vm.requested_radl.systems[0].getValue('net_interface.0.ip'))

        self.assertNotIn("ERROR",
                         self.log.getvalue(),
                         msg="ERROR found in log: %s" % self.log.getvalue())