示例#1
0
文件: test_im_logic.py 项目: nakos/im
    def test_altervm(self):
        """Test AlterVM"""
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("cpu.count", "=", 1),
                Feature("memory.size", "=", 512, "M"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("cpu.count", "=", 2),
                Feature("memory.size", "=", 1024, "M"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        radl_info = IM.AlterVM(infId, "0", str(radl), auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(parsed_radl_info.systems[0].getValue("cpu.count"), 2)
        self.assertEqual(
            parsed_radl_info.systems[0].getFeature('memory.size').getValue(
                'M'), 1024)

        IM.DestroyInfrastructure(infId, auth0)
示例#2
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_cloud_order(self, suds_cli):
        """Test cloud selection in base of the auth data order."""

        n0, n1 = 1, 1  # Machines to deploy
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("cpu.count", "=", 1),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", n0))
        radl.add(
            system("s1", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("cpu.count", "=", 1),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s1", n1))

        cloud0 = self.get_cloud_connector_mock("MyMock0")
        self.register_cloudconnector("Mock0", cloud0)
        cloud1 = self.get_cloud_connector_mock("MyMock1")
        self.register_cloudconnector("Mock1", cloud1)
        auth0 = self.getAuth([0], [0], [("Mock0", 0), ("Mock1", 1)])
        infId = IM.CreateInfrastructure(str(radl), auth0)
        self.assertEqual(cloud0.launch.call_count, n0 + n1)
        IM.DestroyInfrastructure(infId, auth0)
示例#3
0
文件: VMRC.py 项目: buweixiaomi/im
    def _toRADLSystem(vmi):

        # Pass common features
        VMRC_RADL_MAP = {
            'hypervisor': ('virtual_system_type', str),
            'diskSize': ('disk.0.size', int),
            'arch': ('cpu.arch', str),
            'location': ('disk.0.image.url', str),
            'name': ('disk.0.image.name', str),
            'userLogin': ('disk.0.os.credentials.username', str),
            'userPassword': ('disk.0.os.credentials.password', str)
        }
        fs = [Feature(VMRC_RADL_MAP[prop][0], "=", VMRC_RADL_MAP[prop][1](getattr(vmi, prop)))
              for prop in VMRC_RADL_MAP if hasattr(vmi, prop) and getattr(vmi, prop)]
        fs.extend([Feature("disk.0.os." + prop, "=", getattr(vmi.os, prop))
                   for prop in ['name', "flavour", "version"]])

        if not hasattr(vmi, 'applications'):
            return system("", fs)

        # vmi.applications can store the attributes of a single application
        # or can be a list of objects.
        if vmi.applications and isinstance(vmi.applications[0], str):
            apps = [vmi.applications]
        else:
            apps = vmi.applications

        for app in apps:
            OS_VMRC_RADL_PROPS = ["name", "version", "path"]
            fs.append(Feature("disk.0.applications", "contains", FeaturesApp(
                [Feature(prop, "=", getattr(app, prop))
                    for prop in OS_VMRC_RADL_PROPS] +
                [Feature("preinstalled", "=", "yes")])))
        return system("", fs)
示例#4
0
    def test_inf_addresources2(self):
        """Deploy independent virtual machines in two cloud providers."""

        n0, n1 = 2, 5  # Machines to deploy
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(system("s1", [Feature("disk.0.image.url", "=", "mock1://wind.ows.suc.kz"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.private_key", "=", "private_key")]))
        radl.add(deploy("s0", n0))
        radl.add(deploy("s1", n1))

        Config.MAX_SIMULTANEOUS_LAUNCHES = 10

        def concreteSystem(s, cloud_id):
            url = s.getValue("disk.0.image.url")
            return [s.clone()] if url.partition(":")[0] == cloud_id else []
        cloud0 = self.get_cloud_connector_mock("MyMock0")
        cloud0.concreteSystem = lambda _0, s, _1: concreteSystem(s, "mock0")
        self.register_cloudconnector("Mock0", cloud0)
        cloud1 = self.get_cloud_connector_mock("MyMock1")
        cloud1.concreteSystem = lambda _0, s, _1: concreteSystem(s, "mock1")
        self.register_cloudconnector("Mock1", cloud1)
        auth0 = self.getAuth([0], [], [("Mock0", 0), ("Mock1", 1)])
        infId = IM.CreateInfrastructure("", auth0)
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(len(vms), n0 + n1)
        self.assertEqual(cloud0.launch.call_count, n0)
        self.assertEqual(cloud1.launch.call_count, n1)
        for call, _ in cloud0.launch.call_args_list + cloud1.launch.call_args_list:
            self.assertEqual(call[3], 1)
        IM.DestroyInfrastructure(infId, auth0)
示例#5
0
 def test_tosca_add_hybrid2(self):
     tosca_data = read_file_as_string('../files/tosca_add_hybrid.yml')
     tosca = Tosca(tosca_data)
     inf_info = MagicMock()
     vm1 = MagicMock()
     system1 = system("lrms_server", [
         Feature("disk.0.image.url", "=", "ost://cloud1.com/image1"),
         Feature("net_interface.0.connection", "=", "private_net")
     ])
     vm1.info.systems = [system1]
     vm2 = MagicMock()
     system2 = system("lrms_wn", [
         Feature("disk.0.image.url", "=", "ost://cloud3.com/image1"),
         Feature("net_interface.0.connection", "=", "private.cloud3.com")
     ])
     vm2.info.systems = [system2]
     inf_info.get_vm_list_by_system_name.return_value = {
         "lrms_server": [vm1],
         "lrms_wn": [vm2]
     }
     net = MagicMock()
     net.isPublic.return_value = False
     inf_info.radl.get_network_by_id.return_value = net
     _, radl = tosca.to_radl(inf_info)
     print(radl)
     radl = parse_radl(str(radl))
     lrms_wn = radl.get_system_by_name("lrms_wn")
     self.assertEqual("private.cloud2.com",
                      lrms_wn.getValue("net_interface.0.connection"))
示例#6
0
    def test_altervm(self):
        """Test AlterVM"""
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("cpu.count", "=", 1),
                               Feature("memory.size", "=", 512, "M"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("cpu.count", "=", 2),
                               Feature("memory.size", "=", 1024, "M"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 1))

        radl_info = IM.AlterVM(infId, "0", str(radl), auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(parsed_radl_info.systems[0].getValue("cpu.count"), 2)
        self.assertEqual(parsed_radl_info.systems[0].getFeature('memory.size').getValue('M'), 1024)

        IM.DestroyInfrastructure(infId, auth0)
示例#7
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_addresources0(self):
        """Deploy single virtual machines and test reference."""
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure("", auth0)

        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(vms, [0])

        # Test references
        radl = RADL()
        radl.add(system("s0", reference=True))
        radl.add(deploy("s0", 1))
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(vms, [1])

        IM.DestroyInfrastructure(infId, auth0)
示例#8
0
    def complete_radl(self, radl):
        """
        Update passed radl with the stored RADL.
        """

        with self._lock:
            # Replace references of systems, networks and configures by its
            # definitions
            for s in radl.networks + radl.systems + radl.configures + radl.ansible_hosts:
                if s.reference:
                    aspect = self.radl.get(s)
                    if aspect is None:
                        raise Exception(
                            "Unknown reference in RADL to %s '%s'" % (type(s), s.getId()))
                    radl.add(aspect.clone(), "replace")

            # Add fake deploys to indicate the cloud provider associated to a
            # private network.
            system_counter = 0
            for n in radl.networks:
                if n.id in self.private_networks:
                    system_id = self.FAKE_SYSTEM + str(system_counter)
                    system_counter += 1
                    radl.add(
                        system(system_id, [Feature("net_interface.0.connection", "=", n.id)]))
                    radl.add(deploy(system_id, 0, self.private_networks[n.id]))

        # Check the RADL
        radl.check()
示例#9
0
    def test_create_disk_snapshot(self):
        """Test CreateDiskSnapshot """
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        new_url = "mock0://linux.for.ev.er/test"

        cloud0 = self.get_cloud_connector_mock("MyMock0")
        cloud0.create_snapshot = Mock(return_value=(True, new_url))
        self.register_cloudconnector("Mock0", cloud0)
        auth0 = self.getAuth([0], [], [("Mock0", 0)])

        infId = IM.CreateInfrastructure(str(radl), auth0)

        InfrastructureList.infrastructure_list[infId].vm_list[
            0].cloud_connector = cloud0

        res = IM.CreateDiskSnapshot(infId, 0, 0, "test", True, auth0)
        self.assertEqual(res, new_url)

        self.assertEqual(cloud0.create_snapshot.call_count, 1)
示例#10
0
    def test_inf_addresources_without_credentials(self):
        """Deploy single virtual machine without credentials to check that it raises the correct exception."""

        radl = RADL()
        radl.add(
            system(
                "s0",
                [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure("", auth0)

        vms = IM.AddResource(infId, str(radl), auth0)

        self.assertEqual(vms, [0])

        res = IM.GetInfrastructureState(infId, auth0)
        self.assertEqual(res['state'], VirtualMachine.FAILED)

        res = IM.GetVMContMsg(infId, 0, auth0)
        self.assertEqual(res, (
            "Error launching the VMs of type s0 to cloud ID cloud0 of type Dummy."
            " No username for deploy: s0\n"))

        IM.DestroyInfrastructure(infId, auth0)
示例#11
0
文件: test_im_logic.py 项目: nakos/im
    def test_start_stop(self):
        """Test Start and Stop operations"""
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        res = IM.StopInfrastructure(infId, auth0)
        self.assertEqual(res, "")
        res = IM.StartInfrastructure(infId, auth0)
        self.assertEqual(res, "")

        res = IM.StartVM(infId, "0", auth0)
        self.assertEqual(res, "")
        res = IM.StopVM(infId, "0", auth0)
        self.assertEqual(res, "")

        IM.DestroyInfrastructure(infId, auth0)
示例#12
0
    def test_create_async(self):
        """Create Inf. async"""

        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        cloud = type("MyMock0", (CloudConnector, object), {})
        cloud.launch = Mock(side_effect=self.sleep_and_create_vm)
        cloud.finalize = Mock(return_value=(True, ""))
        self.register_cloudconnector("Mock", cloud)
        auth0 = self.getAuth([0], [], [("Mock", 0)])

        before = int(time.time())
        infId = IM.CreateInfrastructure(str(radl), auth0, True)
        delay = int(time.time()) - before

        self.assertLess(delay, 2)

        time.sleep(6)

        IM.DestroyInfrastructure(infId, auth0)
示例#13
0
    def test_60_finalize(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()
        radl = RADL()
        radl.systems.append(system("test"))
        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, _ = occi_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())
示例#14
0
    def test_get_vm_info(self):
        """
        Test GetVMInfo and GetVMProperty and GetVMContMsg and GetInfrastructureRADL and
        GetInfrastructureContMsg and GetInfrastructureState.
        """
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        radl_info = IM.GetVMInfo(infId, "0", auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(parsed_radl_info.systems[0].getValue("state"), "running")

        state = IM.GetVMProperty(infId, "0", "state", auth0)
        self.assertEqual(state, "running")

        contmsg = IM.GetVMContMsg(infId, "0", auth0)
        self.assertEqual(contmsg, "")

        contmsg = IM.GetInfrastructureContMsg(infId, auth0)

        state = IM.GetInfrastructureState(infId, auth0)
        self.assertEqual(state["state"], "running")
        self.assertEqual(state["vm_states"]["0"], "running")

        radl_info = IM.GetInfrastructureRADL(infId, auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(parsed_radl_info.systems[0].getValue("disk.0.os.credentials.username"), "user")

        IM.DestroyInfrastructure(infId, auth0)
示例#15
0
文件: test_im_logic.py 项目: nakos/im
    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"))
示例#16
0
    def complete_radl(self, radl):
        """
        Update passed radl with the stored RADL.
        """

        with self._lock:
            # Replace references of systems, networks and configures by its
            # definitions
            for s in radl.networks + radl.systems + radl.configures + radl.ansible_hosts:
                if s.reference:
                    aspect = self.radl.get(s)
                    if aspect is None:
                        raise Exception(
                            "Unknown reference in RADL to %s '%s'" %
                            (type(s), s.getId()))
                    radl.add(aspect.clone(), "replace")

            # Add fake deploys to indicate the cloud provider associated to a
            # private network.
            system_counter = 0
            for n in radl.networks:
                if n.id in self.private_networks:
                    system_id = self.FAKE_SYSTEM + str(system_counter)
                    system_counter += 1
                    radl.add(
                        system(
                            system_id,
                            [Feature("net_interface.0.connection", "=", n.id)
                             ]))
                    radl.add(deploy(system_id, 0, self.private_networks[n.id]))

        # Check the RADL
        radl.check()
示例#17
0
    def test_get_vm_info(self):
        """
        Test GetVMInfo and GetVMProperty and GetVMContMsg and GetInfrastructureRADL and
        GetInfrastructureContMsg and GetInfrastructureState.
        """
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        radl_info = IM.GetVMInfo(infId, "0", auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(parsed_radl_info.systems[0].getValue("state"),
                         "running")

        radl_info = IM.GetVMInfo(infId, "0", auth0, True)
        parsed_radl_info = parse_radl_json(radl_info)
        self.assertEqual(parsed_radl_info.systems[0].getValue("state"),
                         "running")

        state = IM.GetVMProperty(infId, "0", "state", auth0)
        self.assertEqual(state, "running")

        contmsg = IM.GetVMContMsg(infId, "0", auth0)
        self.assertEqual(contmsg, "")

        InfrastructureList.infrastructure_list[infId].cont_out = "Header"
        InfrastructureList.infrastructure_list[infId].vm_list[
            0].cloud_connector = MagicMock()
        InfrastructureList.infrastructure_list[infId].vm_list[
            0].cloud_connector.error_messages = "TESTMSG"
        contmsg = IM.GetInfrastructureContMsg(infId, auth0)
        header_contmsg = IM.GetInfrastructureContMsg(infId, auth0, True)
        InfrastructureList.infrastructure_list[infId].vm_list[
            0].cloud_connector = None

        self.assertIn("TESTMSG", contmsg)
        self.assertNotIn("TESTMSG", header_contmsg)
        self.assertIn("Header", header_contmsg)

        state = IM.GetInfrastructureState(infId, auth0)
        self.assertEqual(state["state"], "running")
        self.assertEqual(state["vm_states"]["0"], "running")

        radl_info = IM.GetInfrastructureRADL(infId, auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(
            parsed_radl_info.systems[0].getValue(
                "disk.0.os.credentials.username"), "user")

        IM.DestroyInfrastructure(infId, auth0)
示例#18
0
文件: VMRC.py 项目: elcangri2124/im
    def _toRADLSystem(vmi):

        # Pass common features
        VMRC_RADL_MAP = {
            'hypervisor': ('virtual_system_type', str),
            'diskSize': ('disk.0.size', int),
            'arch': ('cpu.arch', str),
            'location': ('disk.0.image.url', str),
            'name': ('disk.0.image.name', str),
            'userLogin': ('disk.0.os.credentials.username', str),
            'userPassword': ('disk.0.os.credentials.password', str)
        }
        fs = [
            Feature(VMRC_RADL_MAP[prop][0], "=",
                    VMRC_RADL_MAP[prop][1](getattr(vmi, prop)))
            for prop in VMRC_RADL_MAP
            if hasattr(vmi, prop) and getattr(vmi, prop)
        ]
        fs.extend([
            Feature("disk.0.os." + prop, "=", getattr(vmi.os, prop))
            for prop in ['name', "flavour", "version"]
        ])

        if not hasattr(vmi, 'applications'):
            return system("", fs)

        # vmi.applications can store the attributes of a single application
        # or can be a list of objects.
        if vmi.applications and isinstance(vmi.applications[0], str):
            apps = [vmi.applications]
        else:
            apps = vmi.applications

        for app in apps:
            OS_VMRC_RADL_PROPS = ["name", "version", "path"]
            fs.append(
                Feature(
                    "disk.0.applications", "contains",
                    FeaturesApp([
                        Feature(prop, "=", getattr(app, prop))
                        for prop in OS_VMRC_RADL_PROPS
                    ] + [Feature("preinstalled", "=", "yes")])))
        return system("", fs)
示例#19
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_addresources2(self):
        """Deploy independent virtual machines in two cloud providers."""

        n0, n1 = 2, 5  # Machines to deploy
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(
            system("s1", [
                Feature("disk.0.image.url", "=", "mock1://wind.ows.suc.kz"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.private_key", "=",
                        "private_key")
            ]))
        radl.add(deploy("s0", n0))
        radl.add(deploy("s1", n1))

        Config.MAX_SIMULTANEOUS_LAUNCHES = 10

        def concreteSystem(s, cloud_id):
            url = s.getValue("disk.0.image.url")
            return [s.clone()] if url.partition(":")[0] == cloud_id else []

        cloud0 = self.get_cloud_connector_mock("MyMock0")
        cloud0.concreteSystem = lambda _0, s, _1: concreteSystem(s, "mock0")
        self.register_cloudconnector("Mock0", cloud0)
        cloud1 = self.get_cloud_connector_mock("MyMock1")
        cloud1.concreteSystem = lambda _0, s, _1: concreteSystem(s, "mock1")
        self.register_cloudconnector("Mock1", cloud1)
        auth0 = self.getAuth([0], [], [("Mock0", 0), ("Mock1", 1)])
        infId = IM.CreateInfrastructure("", auth0)
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(len(vms), n0 + n1)
        self.assertEqual(cloud0.launch.call_count, n0)
        self.assertEqual(cloud1.launch.call_count, n1)
        for call, _ in cloud0.launch.call_args_list + cloud1.launch.call_args_list:
            self.assertEqual(call[3], 1)
        IM.DestroyInfrastructure(infId, auth0)
示例#20
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_addresources3(self, suds_cli):
        """Test cloud selection."""

        n0, n1 = 2, 5  # Machines to deploy
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                SoftFeatures(10, [Feature("memory.size", "<=", 500)]),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(
            system("s1", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                SoftFeatures(10, [Feature("memory.size", ">=", 800)]),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", n0))
        radl.add(deploy("s1", n1))

        Config.MAX_SIMULTANEOUS_LAUNCHES = 10

        def concreteSystem(s, mem):
            return [system(s.name, [Feature("memory.size", "=", mem)])]

        cloud0 = self.get_cloud_connector_mock("MyMock0")
        cloud0.concreteSystem = lambda _0, s, _1: concreteSystem(s, 500)
        self.register_cloudconnector("Mock0", cloud0)
        cloud1 = self.get_cloud_connector_mock("MyMock1")
        cloud1.concreteSystem = lambda _0, s, _1: concreteSystem(s, 1000)
        self.register_cloudconnector("Mock1", cloud1)
        auth0 = self.getAuth([0], [0], [("Mock0", 0), ("Mock1", 1)])
        infId = IM.CreateInfrastructure("", auth0)
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(len(vms), n0 + n1)
        self.assertEqual(cloud0.launch.call_count, n0)
        self.assertEqual(cloud1.launch.call_count, n1)
        for call, _ in cloud0.launch.call_args_list + cloud1.launch.call_args_list:
            self.assertEqual(call[3], 1)
        IM.DestroyInfrastructure(infId, auth0)
示例#21
0
    def test_inf_addresources0(self):
        """Deploy single virtual machines and test reference."""
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure("", auth0)

        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(vms, [0])

        # Test references
        radl = RADL()
        radl.add(system("s0", reference=True))
        radl.add(deploy("s0", 1))
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(vms, [1])

        IM.DestroyInfrastructure(infId, auth0)
示例#22
0
    def test_inf_addresources3(self):
        """Test cloud selection."""

        n0, n1 = 2, 5  # Machines to deploy
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               SoftFeatures(
                                   10, [Feature("memory.size", "<=", 500)]),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(system("s1", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               SoftFeatures(
                                   10, [Feature("memory.size", ">=", 800)]),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", n0))
        radl.add(deploy("s1", n1))

        Config.MAX_SIMULTANEOUS_LAUNCHES = 10

        def concreteSystem(s, mem):
            return [system(s.name, [Feature("memory.size", "=", mem)])]
        cloud0 = self.get_cloud_connector_mock("MyMock0")
        cloud0.concreteSystem = lambda _0, s, _1: concreteSystem(s, 500)
        self.register_cloudconnector("Mock0", cloud0)
        cloud1 = self.get_cloud_connector_mock("MyMock1")
        cloud1.concreteSystem = lambda _0, s, _1: concreteSystem(s, 1000)
        self.register_cloudconnector("Mock1", cloud1)
        auth0 = self.getAuth([0], [0], [("Mock0", 0), ("Mock1", 1)])
        infId = IM.CreateInfrastructure("", auth0)
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(len(vms), n0 + n1)
        self.assertEqual(cloud0.launch.call_count, n0)
        self.assertEqual(cloud1.launch.call_count, n1)
        for call, _ in cloud0.launch.call_args_list + cloud1.launch.call_args_list:
            self.assertEqual(call[3], 1)
        IM.DestroyInfrastructure(infId, auth0)
示例#23
0
    def test_export_import(self):
        """Test ExportInfrastructure and ImportInfrastructure operations"""
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        res = IM.ExportInfrastructure(infId, True, auth0)
        new_inf_id = IM.ImportInfrastructure(res, auth0)

        IM.DestroyInfrastructure(new_inf_id, auth0)
示例#24
0
    def test_inf_cloud_order(self):
        """Test cloud selection in base of the auth data order."""

        n0, n1 = 1, 1  # Machines to deploy
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("cpu.count", "=", 1),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", n0))
        radl.add(system("s1", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("cpu.count", "=", 1),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s1", n1))

        cloud0 = self.get_cloud_connector_mock("MyMock0")
        self.register_cloudconnector("Mock0", cloud0)
        cloud1 = self.get_cloud_connector_mock("MyMock1")
        self.register_cloudconnector("Mock1", cloud1)
        auth0 = self.getAuth([0], [0], [("Mock0", 0), ("Mock1", 1)])
        infId = IM.CreateInfrastructure(str(radl), auth0)
        self.assertEqual(cloud0.launch.call_count, n0 + n1)
        IM.DestroyInfrastructure(infId, auth0)
示例#25
0
    def test_reconfigure(self):
        """Reconfigure."""
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        reconf_radl = """configure test (\n@begin\n---\n  - tasks:\n      - debug: msg="RECONFIGURERADL"\n@end\n)"""
        IM.Reconfigure(infId, reconf_radl, auth0)
        IM.Reconfigure(infId, reconf_radl, auth0, ['0'])

        IM.DestroyInfrastructure(infId, auth0)
示例#26
0
    def test_inf_removeresources(self):
        """Deploy 4 VMs and remove 2"""
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 4))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)
        cont = IM.RemoveResource(infId, ['0', '1'], auth0)
        self.assertEqual(cont, 2)
        vms = IM.GetInfrastructureInfo(infId, auth0)
        self.assertEqual(sorted(vms), ['2', '3'])

        IM.DestroyInfrastructure(infId, auth0)
示例#27
0
    def test_inf_addresources_without_credentials(self):
        """Deploy single virtual machine without credentials to check that it raises the correct exception."""

        radl = RADL()
        radl.add(
            system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure("", auth0)

        with self.assertRaises(Exception) as ex:
            IM.AddResource(infId, str(radl), auth0)

        self.assertIn("No username", ex.exception.message)

        IM.DestroyInfrastructure(infId, auth0)
示例#28
0
文件: test_im_logic.py 项目: nakos/im
    def test_export_import(self):
        """Test ExportInfrastructure and ImportInfrastructure operations"""
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        res = IM.ExportInfrastructure(infId, True, auth0)
        new_inf_id = IM.ImportInfrastructure(res, auth0)

        IM.DestroyInfrastructure(new_inf_id, auth0)
示例#29
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_addresources_without_credentials(self):
        """Deploy single virtual machine without credentials to check that it raises the correct exception."""

        radl = RADL()
        radl.add(
            system(
                "s0",
                [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure("", auth0)

        with self.assertRaises(Exception) as ex:
            IM.AddResource(infId, str(radl), auth0)

        self.assertIn("No username", str(ex.exception))

        IM.DestroyInfrastructure(infId, auth0)
示例#30
0
文件: test_im_logic.py 项目: nakos/im
    def test_reconfigure(self):
        """Reconfigure."""
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        reconf_radl = """configure test (\n@begin\n---\n  - tasks:\n      - debug: msg="RECONFIGURERADL"\n@end\n)"""
        IM.Reconfigure(infId, reconf_radl, auth0)
        IM.Reconfigure(infId, reconf_radl, auth0, ['0'])

        IM.DestroyInfrastructure(infId, auth0)
示例#31
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_removeresources(self):
        """Deploy 4 VMs and remove 2"""
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 4))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)
        cont = IM.RemoveResource(infId, ['0', '1'], auth0)
        self.assertEqual(cont, 2)
        vms = IM.GetInfrastructureInfo(infId, auth0)
        self.assertEqual(sorted(vms), ['2', '3'])

        IM.DestroyInfrastructure(infId, auth0)
示例#32
0
    def test_inf_addresources1(self):
        """Deploy n independent virtual machines."""

        n = 20  # Machines to deploy
        Config.MAX_SIMULTANEOUS_LAUNCHES = n / 2  # Test the pool
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", n))
        cloud = self.get_cloud_connector_mock()
        self.register_cloudconnector("Mock", cloud)
        auth0 = self.getAuth([0], [], [("Mock", 0)])
        infId = IM.CreateInfrastructure("", auth0)
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(len(vms), n)
        self.assertEqual(cloud.launch.call_count, n)
        for call, _ in cloud.launch.call_args_list:
            self.assertEqual(call[3], 1)
        IM.DestroyInfrastructure(infId, auth0)
示例#33
0
    def test_get_vm_info(self):
        """
        Test GetVMInfo and GetVMProperty and GetVMContMsg and GetInfrastructureRADL and
        GetInfrastructureContMsg and GetInfrastructureState.
        """
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        radl_info = IM.GetVMInfo(infId, "0", auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(parsed_radl_info.systems[0].getValue("state"),
                         "running")

        state = IM.GetVMProperty(infId, "0", "state", auth0)
        self.assertEqual(state, "running")

        contmsg = IM.GetVMContMsg(infId, "0", auth0)
        self.assertEqual(contmsg, "")

        contmsg = IM.GetInfrastructureContMsg(infId, auth0)

        state = IM.GetInfrastructureState(infId, auth0)
        self.assertEqual(state["state"], "running")
        self.assertEqual(state["vm_states"]["0"], "running")

        radl_info = IM.GetInfrastructureRADL(infId, auth0)
        parsed_radl_info = parse_radl(str(radl_info))
        self.assertEqual(
            parsed_radl_info.systems[0].getValue(
                "disk.0.os.credentials.username"), "user")

        IM.DestroyInfrastructure(infId, auth0)
示例#34
0
    def test_start_stop(self):
        """Test Start and Stop operations"""
        radl = RADL()
        radl.add(system("s0", [Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                               Feature("disk.0.os.credentials.username", "=", "user"),
                               Feature("disk.0.os.credentials.password", "=", "pass")]))
        radl.add(deploy("s0", 1))

        auth0 = self.getAuth([0], [], [("Dummy", 0)])
        infId = IM.CreateInfrastructure(str(radl), auth0)

        res = IM.StopInfrastructure(infId, auth0)
        self.assertEqual(res, "")
        res = IM.StartInfrastructure(infId, auth0)
        self.assertEqual(res, "")

        res = IM.StartVM(infId, "0", auth0)
        self.assertEqual(res, "")
        res = IM.StopVM(infId, "0", auth0)
        self.assertEqual(res, "")

        IM.DestroyInfrastructure(infId, auth0)
示例#35
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_addresources1(self):
        """Deploy n independent virtual machines."""

        n = 20  # Machines to deploy
        Config.MAX_SIMULTANEOUS_LAUNCHES = int(n / 2)  # Test the pool
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", n))
        cloud = self.get_cloud_connector_mock()
        self.register_cloudconnector("Mock", cloud)
        auth0 = self.getAuth([0], [], [("Mock", 0)])
        infId = IM.CreateInfrastructure("", auth0)
        vms = IM.AddResource(infId, str(radl), auth0)
        self.assertEqual(len(vms), n)
        self.assertEqual(cloud.launch.call_count, n)
        for call, _ in cloud.launch.call_args_list:
            self.assertEqual(call[3], 1)
        IM.DestroyInfrastructure(infId, auth0)
示例#36
0
文件: OCCI.py 项目: indigo-dc/im
    def test_60_finalize(self, delete_proxy, get_keystone_uri, connection):
        auth = Authentication([{'id': 'occi', 'type': 'OCCI', 'proxy': 'proxy', 'host': 'https://server.com:11443'}])
        occi_cloud = self.get_occi_cloud()

        inf = MagicMock()
        inf.get_next_vm_id.return_value = 1
        radl = RADL()
        radl.systems.append(system("test"))
        vm = VirtualMachine(inf, "1", occi_cloud.cloud, radl, radl, occi_cloud)

        conn = MagicMock()
        connection.return_value = conn

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

        get_keystone_uri.return_value = None

        success, _ = occi_cloud.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()
示例#37
0
文件: test_im_logic.py 项目: nakos/im
    def test_inf_addresources4(self):
        """Deploy a virtual machine when the first cloud provider fails."""

        radl = RADL()
        radl.add(
            system("s0", [
                Feature(
                    "disk.0.image.url", "=",
                    ["mock0://linux.for.ev.er", "mock1://linux.for.ev.er"]),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))
        cloud0 = self.get_cloud_connector_mock("MyMock0")
        self.register_cloudconnector("Mock0", cloud0)
        cloud1 = type("MyMock1", (CloudConnector, object), {})
        cloud1.launch = Mock(return_value=[(False, "Error")])
        self.register_cloudconnector("Mock1", cloud1)
        auth0 = self.getAuth([0], [], [("Mock1", 1), ("Mock0", 0)])

        n = 3
        Config.MAX_VM_FAILS = n
        infId = IM.CreateInfrastructure("", auth0)
        vms = IM.AddResource(infId, str(radl), auth0)
        Config.MAX_VM_FAILS = 1

        self.assertEqual(len(vms), 1)
        # The first attempt in cloud 0 fails
        self.assertEqual(cloud0.launch.call_count, 1)
        # The rest of attempts are in cloud 1
        self.assertEqual(cloud1.launch.call_count, n)
        for call, _ in cloud0.launch.call_args_list:
            self.assertEqual(call[3], 1)
        for call, _ in cloud1.launch.call_args_list:
            self.assertEqual(call[3], 1)

        IM.DestroyInfrastructure(infId, auth0)
示例#38
0
    def test_get_cloud_init_data(self):
        cloud_init = """
groups:
  - ubuntu: [foo,bar]
  - cloud-users
# Add users to the system. Users are added after groups are added.
users:
  - default
  - name: cloudy
    gecos: Magic Cloud App Daemon User
    inactive: true
    system: true
  - snapuser: [email protected]
packages:
 - pwgen
 - pastebinit
 - [libpython2.7, 2.7.3-0ubuntu3.1]
 """

        expected_res = """#cloud-config
merge_how: list(append)+dict(recurse_array,no_replace)+str()
users:
- homedir: /opt/user
  lock-passwd: true
  name: user
  ssh-authorized-keys:
  - pub_key
  ssh-import-id: user
  sudo: ALL=(ALL) NOPASSWD:ALL
"""
        occi_cloud = self.get_occi_cloud()
        res = occi_cloud.get_cloud_init_data(None, None, "pub_key", "user")
        self.assertEqual(res, expected_res)

        radl_data = """
system node ()
configure node (
@begin
#!/bin/sh
touch /tmp/hello
@end
)
deploy node 1
contextualize (
    system node configure node with cloud_init
)"""
        radl = radl_parse.parse_radl(radl_data)
        occi_cloud = self.get_occi_cloud()
        res = occi_cloud.get_cloud_init_data(radl)
        self.assertEqual(res, "#!/bin/sh\ntouch /tmp/hello")

        expected_res = """#cloud-config
groups:
- ubuntu:
  - foo
  - bar
- cloud-users
merge_how: list(append)+dict(recurse_array,no_replace)+str()
packages:
- pwgen
- pastebinit
- - libpython2.7
  - 2.7.3-0ubuntu3.1
users:
- default
- gecos: Magic Cloud App Daemon User
  inactive: true
  name: cloudy
  system: true
- snapuser: [email protected]
- homedir: /opt/user
  lock-passwd: true
  name: user
  ssh-authorized-keys:
  - pub_key
  ssh-import-id: user
  sudo: ALL=(ALL) NOPASSWD:ALL
"""
        radl = RADL()
        radl.systems.append(system("test"))
        citem = contextualize_item("test", "cid", ctxt_tool="cloud_init")
        radl.contextualize.items = {"id": citem}
        radl.configures.append(configure("cid", cloud_init))
        res = occi_cloud.get_cloud_init_data(radl, None, "pub_key", "user")
        self.assertEqual(res, expected_res)
示例#39
0
文件: test_im_logic.py 项目: nakos/im
 def concreteSystem(s, mem):
     return [system(s.name, [Feature("memory.size", "=", mem)])]
示例#40
0
文件: test_im.py 项目: victorsndvg/im
    def test_inf_lifecycle(self):
        """Test Infrastructure lifecycle"""
        radl = """"
            network publica (outbound = 'yes')

            system front (
            cpu.arch='x86_64' and
            cpu.count>=1 and
            memory.size>=512m and
            net_interface.0.connection = 'publica' and
            net_interface.0.ip = '10.0.0.1' 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' and
            disk.1.size=1GB and
            disk.1.device='hdb' and
            disk.1.fstype='ext4' and
            disk.1.mount_path='/mnt/disk' and
            disk.0.applications contains (name = 'ansible.modules.micafer.hadoop') and
            disk.0.applications contains (name='gmetad') and
            disk.0.applications contains (name='wget')
            )

            deploy front 1
        """

        auth0 = self.getAuth([0], [], [("Mock", 0)])
        IM._reinit()
        Config.PLAYBOOK_RETRIES = 1
        Config.CONTEXTUALIZATION_DIR = os.path.dirname(
            os.path.realpath(__file__)) + "/../../contextualization"
        Config.CONFMAMAGER_CHECK_STATE_INTERVAL = 0.001
        cloud0 = self.get_cloud_connector_mock("MyMock")
        self.register_cloudconnector("Mock", cloud0)

        infId = IM.CreateInfrastructure(str(radl), auth0)

        time.sleep(15)

        state = IM.GetInfrastructureState(infId, auth0)
        self.assertEqual(state["state"], "unconfigured")

        InfrastructureList.infrastructure_list[infId].ansible_configured = True

        IM.Reconfigure(infId, "", auth0)

        time.sleep(2)

        state = IM.GetInfrastructureState(infId, auth0)
        self.assertEqual(state["state"], "running")

        add_radl = RADL()
        add_radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        add_radl.add(deploy("s0", 1))

        vms = IM.AddResource(infId, str(add_radl), auth0)
        self.assertEqual(vms, [1])

        state = IM.GetVMProperty(infId, "1", "state", auth0)
        self.assertEqual(state, "running")

        contmsg = IM.GetVMContMsg(infId, "1", auth0)
        self.assertEqual(contmsg, "")

        cont = IM.RemoveResource(infId, ['1'], auth0)
        self.assertEqual(cont, 1)

        IM.DestroyInfrastructure(infId, auth0)
示例#41
0
    def test_inf_creation_errors(self):
        """Create infrastructure with errors"""

        radl = """"
            network publica (outbound = 'yes')
            network privada ()
            system front (
            net_interface.0.connection = 'publica' and
            net_interface.1.connection = 'privada' and
            disk.0.image.url = ['one://localhost/image', 'http://localhost:443/image'] and
            disk.0.os.credentials.username = '******'
            )
            system wn (
            net_interface.0.connection = 'privada' and
            disk.0.image.url = ['one://localhost/image', 'http://localhost:443/image'] and
            disk.0.os.credentials.username = '******'
            )
            deploy front 1
            deploy wn 1
        """

        # this case raises an exception
        auth0 = Authentication([{
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        with self.assertRaises(Exception) as ex:
            IM.CreateInfrastructure(radl, auth0)

        self.assertEqual(str(ex.exception), "No cloud provider available")

        # this case must fail with "no concrete system" error
        auth0 = Authentication([{
            'id': 'ost',
            'type': 'OpenStack',
            'username': '******',
            'password': '******',
            'tenant': 'ten',
            'host': 'localhost:5000'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])

        with self.assertRaises(Exception) as ex:
            IM.CreateInfrastructure(radl, auth0)
        self.assertIn(
            'Error launching the VMs of type front to cloud ID ost of type OpenStack.'
            ' Error, no concrete system to deploy: front in cloud: ost. '
            'Check if a correct image is being used', str(ex.exception))

        # this case must work OK
        auth0 = Authentication([{
            'id': 'dummy',
            'type': 'Dummy'
        }, {
            'type': 'InfrastructureManager',
            'username': '******',
            'password': '******'
        }])
        IM.CreateInfrastructure(radl, auth0)

        Config.MAX_VM_FAILS = 3
        radl = RADL()
        radl.add(
            system("s0", [
                Feature("disk.0.image.url", "=", "mock0://linux.for.ev.er"),
                Feature("disk.0.os.credentials.username", "=", "user"),
                Feature("disk.0.os.credentials.password", "=", "pass")
            ]))
        radl.add(deploy("s0", 1))
        cloud = type("MyMock0", (CloudConnector, object), {})
        cloud.launch = Mock(return_value=[(False, "e1")])
        cloud.finalize = Mock(return_value=(True, ""))
        self.register_cloudconnector("Mock", cloud)
        auth0 = self.getAuth([0], [], [("Mock", 0)])

        with self.assertRaises(Exception) as ex:
            IM.CreateInfrastructure(str(radl), auth0)

        self.assertIn((
            "Error launching the VMs of type s0 to cloud ID cloud0 of type Mock. "
            "Attempt 1: e1\nAttempt 2: e1\nAttempt 3: e1"), str(ex.exception))

        self.assertEqual(cloud.finalize.call_count, 1)
示例#42
0
 def concreteSystem(s, mem):
     return [system(s.name, [Feature("memory.size", "=", mem)])]