Esempio n. 1
0
 def testSpice(self):
     instance = objects.Instance(name="kvm.example.com",
                                 primary_node="node7235",
                                 network_port=11000)
     node = objects.Node(name="node7235", uuid="node7235-uuid", ndparams={})
     group = objects.NodeGroup(name="group0132", ndparams={})
     hvparams = {
         constants.HV_SERIAL_CONSOLE: False,
         constants.HV_VNC_BIND_ADDRESS: None,
         constants.HV_KVM_SPICE_BIND: "192.0.2.1",
     }
     cons = self.MakeConsole(instance, node, group, hvparams)
     self.assertEqual(cons.kind, constants.CONS_SPICE)
     self.assertEqual(cons.host, "192.0.2.1")
     self.assertEqual(cons.port, 11000)
Esempio n. 2
0
 def testSerial(self):
     instance = objects.Instance(name="kvm.example.com",
                                 primary_node="node6017-uuid")
     node = objects.Node(name="node6017", uuid="node6017-uuid", ndparams={})
     group = objects.NodeGroup(name="group6134", ndparams={})
     hvparams = {
         constants.HV_SERIAL_CONSOLE: True,
         constants.HV_VNC_BIND_ADDRESS: None,
         constants.HV_KVM_SPICE_BIND: None,
     }
     cons = self.MakeConsole(instance, node, group, hvparams)
     self.assertEqual(cons.kind, constants.CONS_SSH)
     self.assertEqual(cons.host, node.name)
     self.assertEqual(cons.command[0], pathutils.KVM_CONSOLE_WRAPPER)
     self.assertEqual(cons.command[1], constants.SOCAT_PATH)
Esempio n. 3
0
 def testNoConsole(self):
     instance = objects.Instance(name="kvm.example.com",
                                 primary_node="node24325",
                                 network_port=0)
     node = objects.Node(name="node24325",
                         uuid="node24325-uuid",
                         ndparams={})
     group = objects.NodeGroup(name="group9184", ndparams={})
     hvparams = {
         constants.HV_SERIAL_CONSOLE: False,
         constants.HV_VNC_BIND_ADDRESS: None,
         constants.HV_KVM_SPICE_BIND: None,
     }
     cons = self.MakeConsole(instance, node, group, hvparams)
     self.assertEqual(cons.kind, constants.CONS_MESSAGE)
 def testVnc(self):
     instance = objects.Instance(name="kvm.example.com",
                                 primary_node="node7235-uuid",
                                 network_port=constants.VNC_BASE_PORT + 10)
     node = objects.Node(name="node7235", uuid="node7235-uuid", ndparams={})
     group = objects.NodeGroup(name="group3632", ndparams={})
     hvparams = {
         constants.HV_SERIAL_CONSOLE: False,
         constants.HV_VNC_BIND_ADDRESS: "192.0.2.1",
         constants.HV_KVM_SPICE_BIND: None,
     }
     cons = self._Test(instance, node, group, hvparams)
     self.assertEqual(cons.kind, constants.CONS_VNC)
     self.assertEqual(cons.host, "192.0.2.1")
     self.assertEqual(cons.port, constants.VNC_BASE_PORT + 10)
     self.assertEqual(cons.display, 10)
Esempio n. 5
0
    def testFillHvFullMerge(self):
        inst_hvparams = {
            "blah": "blubb",
        }

        fake_dict = constants.HVC_DEFAULTS[constants.HT_FAKE].copy()
        fake_dict.update({
            "foo": "baz",
            "bar": "foo",
            "foobar": "foobar",
            "blah": "blubb",
            "blubb": "blah",
        })
        fake_inst = objects.Instance(name="foobar",
                                     os="lenny-image",
                                     hypervisor=constants.HT_FAKE,
                                     hvparams=inst_hvparams)
        self.assertEqual(fake_dict, self.fake_cl.FillHV(fake_inst))
    def testUpdateInstance(self):
        """Test updates on one instance object"""
        cfg = self._get_object_mock()
        # construct a fake instance
        inst = self._create_instance(cfg)
        fake_instance = objects.Instance()
        # fail if we didn't read the config
        self.failUnlessRaises(errors.ConfigurationError, cfg.Update,
                              fake_instance, None)

        cfg.AddInstance(inst, "my-job")
        instance = cfg.GetInstanceInfo(cfg.GetInstanceList()[0])
        # first pass, must not fail
        cfg.Update(instance, None)
        # second pass, also must not fail (after the config has been written)
        cfg.Update(instance, None)
        # but the fake_instance update should still fail
        self.failUnlessRaises(errors.ConfigurationError, cfg.Update,
                              fake_instance, None)
Esempio n. 7
0
    def testNodesPlainDisks(self):
        inst = objects.Instance(name="fakeinstplain.example.com",
                                primary_node="node3.example.com",
                                disks=[
                                    objects.Disk(dev_type=constants.DT_PLAIN,
                                                 size=128,
                                                 logical_id=("myxenvg",
                                                             "disk25494")),
                                    objects.Disk(dev_type=constants.DT_PLAIN,
                                                 size=512,
                                                 logical_id=("myxenvg",
                                                             "disk29071")),
                                ])

        self._GenericCheck(inst)
        self.assertEqual(len(inst.secondary_nodes), 0)
        self.assertEqual(set(inst.all_nodes), set([inst.primary_node]))
        self.assertEqual(inst.MapLVsByNode(), {
            inst.primary_node: ["myxenvg/disk25494", "myxenvg/disk29071"],
        })
Esempio n. 8
0
    def testNodesDrbdDisks(self):
        inst = objects.Instance(
            name="fakeinstdrbd.example.com",
            primary_node="node10.example.com",
            disks=[
                objects.Disk(dev_type=constants.DT_DRBD8,
                             size=786432,
                             logical_id=("node10.example.com",
                                         "node15.example.com", 12300, 0, 0,
                                         "secret"),
                             children=[
                                 objects.Disk(dev_type=constants.DT_PLAIN,
                                              size=786432,
                                              logical_id=("myxenvg", "disk0")),
                                 objects.Disk(dev_type=constants.DT_PLAIN,
                                              size=128,
                                              logical_id=("myxenvg", "meta0"))
                             ],
                             iv_name="disk/0")
            ])

        self._GenericCheck(inst)
        self.assertEqual(set(inst.secondary_nodes),
                         set(["node15.example.com"]))
        self.assertEqual(set(inst.all_nodes),
                         set([inst.primary_node, "node15.example.com"]))
        self.assertEqual(
            inst.MapLVsByNode(), {
                inst.primary_node: ["myxenvg/disk0", "myxenvg/meta0"],
                "node15.example.com": ["myxenvg/disk0", "myxenvg/meta0"],
            })

        self.assertEqual(inst.FindDisk(0), inst.disks[0])
        self.assertRaises(errors.OpPrereqError, inst.FindDisk, "hello")
        self.assertRaises(errors.OpPrereqError, inst.FindDisk, 100)
        self.assertRaises(errors.OpPrereqError, inst.FindDisk, 1)
Esempio n. 9
0
    def AddNewInstance(self,
                       uuid=None,
                       name=None,
                       primary_node=None,
                       os=None,
                       hypervisor=None,
                       hvparams=None,
                       beparams=None,
                       osparams=None,
                       osparams_private=None,
                       admin_state=None,
                       admin_state_source=None,
                       nics=None,
                       disks=None,
                       disk_template=None,
                       disks_active=None,
                       network_port=None,
                       secondary_node=None):
        """Add a new L{objects.Instance} to the cluster configuration

    See L{objects.Instance} for parameter documentation.

    @rtype: L{objects.Instance}
    @return: the newly added instance

    """
        inst_id = self._cur_inst_id
        self._cur_inst_id += 1

        if uuid is None:
            uuid = self._GetUuid()
        if name is None:
            name = "mock_inst_%d.example.com" % inst_id
        if primary_node is None:
            primary_node = self._master_node.uuid
        primary_node = self._GetObjUuid(primary_node)
        if os is None:
            os = self.GetDefaultOs().name + objects.OS.VARIANT_DELIM +\
                 self.GetDefaultOs().supported_variants[0]
        if hypervisor is None:
            hypervisor = self.GetClusterInfo().enabled_hypervisors[0]
        if hvparams is None:
            hvparams = {}
        if beparams is None:
            beparams = {}
        if osparams is None:
            osparams = {}
        if osparams_private is None:
            osparams_private = {}
        if admin_state is None:
            admin_state = constants.ADMINST_DOWN
        if admin_state_source is None:
            admin_state_source = constants.ADMIN_SOURCE
        if nics is None:
            nics = [self.CreateNic()]
        if disk_template is None:
            if disks is None:
                # user chose nothing, so create a plain disk for him
                disk_template = constants.DT_PLAIN
            elif len(disks) == 0:
                disk_template = constants.DT_DISKLESS
            else:
                disk_template = disks[0].dev_type
        if disks is None:
            if disk_template == constants.DT_DISKLESS:
                disks = []
            else:
                disks = [
                    self.CreateDisk(dev_type=disk_template,
                                    primary_node=primary_node,
                                    secondary_node=secondary_node)
                ]
        if disks_active is None:
            disks_active = admin_state == constants.ADMINST_UP

        inst = objects.Instance(uuid=uuid,
                                name=name,
                                primary_node=primary_node,
                                os=os,
                                hypervisor=hypervisor,
                                hvparams=hvparams,
                                beparams=beparams,
                                osparams=osparams,
                                osparams_private=osparams_private,
                                admin_state=admin_state,
                                admin_state_source=admin_state_source,
                                nics=nics,
                                disks=[],
                                disks_active=disks_active,
                                network_port=network_port)
        self.AddInstance(inst, None)
        for disk in disks:
            self.AddInstanceDisk(inst.uuid, disk)
        return inst
Esempio n. 10
0
    def testEncodeInstance(self):
        cluster = objects.Cluster(hvparams={
            constants.HT_KVM: {
                constants.HV_CDROM_IMAGE_PATH: "foo",
            },
        },
                                  beparams={
                                      constants.PP_DEFAULT: {
                                          constants.BE_MAXMEM: 8192,
                                      },
                                  },
                                  os_hvp={},
                                  osparams={
                                      "linux": {
                                          "role": "unknown",
                                      },
                                  })
        cluster.UpgradeConfig()

        inst = objects.Instance(name="inst1.example.com",
                                hypervisor=constants.HT_KVM,
                                os="linux",
                                hvparams={
                                    constants.HV_CDROM_IMAGE_PATH: "bar",
                                    constants.HV_ROOT_PATH: "/tmp",
                                },
                                beparams={
                                    constants.BE_MINMEM: 128,
                                    constants.BE_MAXMEM: 256,
                                },
                                nics=[
                                    objects.NIC(nicparams={
                                        constants.NIC_MODE: "mymode",
                                    }),
                                ],
                                disk_template=constants.DT_PLAIN,
                                disks=["disk_uuid_1", "disk_uuid_2"])
        inst.UpgradeConfig()

        cfg = _FakeConfigForRpcRunner(cluster=cluster)
        runner = rpc.RpcRunner(cfg,
                               None,
                               _req_process_fn=NotImplemented,
                               _getents=mocks.FakeGetentResolver)

        def _CheckBasics(result):
            self.assertEqual(result["name"], "inst1.example.com")
            self.assertEqual(result["os"], "linux")
            self.assertEqual(result["beparams"][constants.BE_MINMEM], 128)
            self.assertEqual(len(result["nics"]), 1)
            self.assertEqual(
                result["nics"][0]["nicparams"][constants.NIC_MODE], "mymode")

        # Generic object serialization
        result = runner._encoder(NotImplemented,
                                 (rpc_defs.ED_OBJECT_DICT, inst))
        _CheckBasics(result)
        self.assertEqual(len(result["hvparams"]), 2)

        result = runner._encoder(NotImplemented,
                                 (rpc_defs.ED_OBJECT_DICT_LIST, 5 * [inst]))
        map(_CheckBasics, result)
        map(lambda r: self.assertEqual(len(r["hvparams"]), 2), result)

        # Just an instance
        result = runner._encoder(NotImplemented, (rpc_defs.ED_INST_DICT, inst))
        _CheckBasics(result)
        self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256)
        self.assertEqual(result["hvparams"][constants.HV_CDROM_IMAGE_PATH],
                         "bar")
        self.assertEqual(result["hvparams"][constants.HV_ROOT_PATH], "/tmp")
        self.assertEqual(result["osparams"], {
            "role": "unknown",
        })
        self.assertEqual(len(result["hvparams"]),
                         len(constants.HVC_DEFAULTS[constants.HT_KVM]))

        # Instance with OS parameters
        result = runner._encoder(NotImplemented, (rpc_defs.ED_INST_DICT_OSP_DP,
                                                  (inst, {
                                                      "role": "webserver",
                                                      "other": "field",
                                                  })))
        _CheckBasics(result)
        self.assertEqual(result["beparams"][constants.BE_MAXMEM], 256)
        self.assertEqual(result["hvparams"][constants.HV_CDROM_IMAGE_PATH],
                         "bar")
        self.assertEqual(result["hvparams"][constants.HV_ROOT_PATH], "/tmp")
        self.assertEqual(result["osparams"], {
            "role": "webserver",
            "other": "field",
        })

        # Instance with hypervisor and backend parameters
        result = runner._encoder(NotImplemented,
                                 (rpc_defs.ED_INST_DICT_HVP_BEP_DP,
                                  (inst, {
                                      constants.HT_KVM: {
                                          constants.HV_BOOT_ORDER: "xyz",
                                      },
                                  }, {
                                      constants.BE_VCPUS: 100,
                                      constants.BE_MAXMEM: 4096,
                                  })))
        _CheckBasics(result)
        self.assertEqual(result["beparams"][constants.BE_MAXMEM], 4096)
        self.assertEqual(result["beparams"][constants.BE_VCPUS], 100)
        self.assertEqual(result["hvparams"][constants.HT_KVM], {
            constants.HV_BOOT_ORDER: "xyz",
        })
        del result["disks_info"][0]["ctime"]
        del result["disks_info"][0]["mtime"]
        del result["disks_info"][1]["ctime"]
        del result["disks_info"][1]["mtime"]
        self.assertEqual(
            result["disks_info"],
            [{
                "dev_type": constants.DT_PLAIN,
                "dynamic_params": {},
                "size": 4096,
                "logical_id": ("vg", "disk6120"),
                "params": constants.DISK_DT_DEFAULTS[inst.disk_template],
                "serial_no": 1,
                "uuid": "disk_uuid_1",
            }, {
                "dev_type": constants.DT_PLAIN,
                "dynamic_params": {},
                "size": 1024,
                "logical_id": ("vg", "disk8508"),
                "params": constants.DISK_DT_DEFAULTS[inst.disk_template],
                "serial_no": 1,
                "uuid": "disk_uuid_2",
            }])

        inst_disks = cfg.GetInstanceDisks(inst.uuid)
        self.assertTrue(compat.all(disk.params == {} for disk in inst_disks),
                        msg="Configuration objects were modified")