Exemplo n.º 1
0
    def test_vnc_port(self):
        vmm = Fvm(MagicMock())
        vm_id = str(uuid.uuid4())
        flavor = Flavor("vm", [
            QuotaLineItem("vm.cpu", 1, Unit.COUNT),
            QuotaLineItem("vm.memory", 8, Unit.GB)
        ])
        spec = vmm.create_vm_spec(vm_id, "ds-1", flavor, image_id="image_id")
        vmm.create_vm(vm_id, spec)
        port = vmm.get_vnc_port(vm_id)
        assert_that(port, none())

        expected = set(range(5900, 5905))
        for p in expected:
            vm_id = str(uuid.uuid4())
            spec = vmm.create_vm_spec(vm_id,
                                      "ds-1",
                                      flavor,
                                      image_id="image_id")
            vmm.set_vnc_port(spec, p)
            vmm.create_vm(vm_id, spec)
            port = vmm.get_vnc_port(vm_id)
            assert_that(port, equal_to(p))

        ports = vmm.get_occupied_vnc_ports()
        # The following 2 asserts test equality of ports and expected
        assert_that(len(ports), equal_to(len(expected)))
        assert_that(len(ports), equal_to(len(expected.union(ports))))
 def test_vminfo(self):
     vmm = Fvm(MagicMock())
     vm_id = str(uuid.uuid4())
     flavor = Flavor("vm", [QuotaLineItem("vm.cpu", 1, Unit.COUNT),
                            QuotaLineItem("vm.memory", 8, Unit.GB)])
     vm_metadata = {
         "project": "p1",
         "vendor": "v1",
     }
     spec = vmm.create_vm_spec(vm_id, "ds-1", flavor, image_id="image_id")
     vmm.set_vminfo(spec, vm_metadata)
     vmm.create_vm(vm_id, spec)
     got_metadata = vmm.get_vminfo(vm_id)
     assert_that(got_metadata, equal_to(vm_metadata))
    def test_vnc_port(self):
        vmm = Fvm(MagicMock())
        vm_id = str(uuid.uuid4())
        flavor = Flavor("vm", [QuotaLineItem("vm.cpu", 1, Unit.COUNT),
                               QuotaLineItem("vm.memory", 8, Unit.GB)])
        spec = vmm.create_vm_spec(vm_id, "ds-1", flavor, image_id="image_id")
        vmm.create_vm(vm_id, spec)
        port = vmm.get_vnc_port(vm_id)
        assert_that(port, none())

        expected = set(range(5900, 5905))
        for p in expected:
            vm_id = str(uuid.uuid4())
            spec = vmm.create_vm_spec(vm_id, "ds-1", flavor,
                                      image_id="image_id")
            vmm.set_vnc_port(spec, p)
            vmm.create_vm(vm_id, spec)
            port = vmm.get_vnc_port(vm_id)
            assert_that(port, equal_to(p))

        ports = vmm.get_occupied_vnc_ports()
        # The following 2 asserts test equality of ports and expected
        assert_that(len(ports), equal_to(len(expected)))
        assert_that(len(ports), equal_to(len(expected.union(ports))))
Exemplo n.º 4
0
 def test_vminfo(self):
     vmm = Fvm(MagicMock())
     vm_id = str(uuid.uuid4())
     flavor = Flavor("vm", [
         QuotaLineItem("vm.cpu", 1, Unit.COUNT),
         QuotaLineItem("vm.memory", 8, Unit.GB)
     ])
     vm_metadata = {
         "project": "p1",
         "vendor": "v1",
     }
     spec = vmm.create_vm_spec(vm_id, "ds-1", flavor, image_id="image_id")
     vmm.set_vminfo(spec, vm_metadata)
     vmm.create_vm(vm_id, spec)
     got_metadata = vmm.get_vminfo(vm_id)
     assert_that(got_metadata, equal_to(vm_metadata))