Пример #1
0
    def test_server_start_stop(self):
        server_plugin.start()
        server = self.assert_server_exist_and_get(self.ctx.node.id)
        self.assert_server_started(server)

        server_plugin.stop()
        self.assert_server_stopped(server)

        server_plugin.start()
        self.assert_server_started(server)
Пример #2
0
    def test_server_resize_up(self):
        old_cpus = self.ctx.node.properties['server']['cpus']
        old_memory = self.ctx.node.properties['server']['memory']
        new_cpus = old_cpus + 1
        new_memory = old_memory + 64

        server_plugin.start()
        server = self.assert_server_exist_and_get(self.ctx.node.id)
        self.assertEqual(old_cpus, server.config.hardware.numCPU)
        self.assertEqual(old_memory, server.config.hardware.memoryMB)
        self.ctx.instance.runtime_properties['cpus'] = new_cpus
        self.ctx.instance.runtime_properties['memory'] = new_memory

        server_plugin.stop()

        server_plugin.resize()

        server = self.assert_server_exist_and_get(self.ctx.node.id)
        self.assertEqual(new_cpus, server.config.hardware.numCPU)
        self.assertEqual(new_memory, server.config.hardware.memoryMB)
Пример #3
0
    def test_stop(self, smart_m):
        conn_mock = mock.Mock()
        smart_m.return_value = conn_mock
        ctx = self._gen_ctx()

        # stop for external
        ctx.instance.runtime_properties['use_external_resource'] = True
        server.stop(server={"name": "server_name"},
                    os_family="other_os")

        # nosuch vm
        ctx.instance.runtime_properties['use_external_resource'] = False
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_name",
            mock.Mock(return_value=None)
        ):
            with self.assertRaisesRegexp(
                NonRecoverableError,
                "Cannot stop server - server doesn't exist for node: "
                "node_name"
            ):
                server.stop(server={"name": "server_name"},
                            os_family="other_os")

        # with poweredoff vm
        vm = mock.Mock()
        vm.obj.summary.runtime.powerState = "PoweredOFF"
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_name",
            mock.Mock(return_value=vm)
        ):
            server.stop(server={"name": "server_name"},
                        os_family="other_os")

        # with poweredon vm
        vm = mock.Mock()
        task = mock.Mock()
        task.info.state = vim.TaskInfo.State.success
        vm.obj.snapshot = None  # no snapshots
        vm.obj.PowerOff = mock.Mock(return_value=task)
        vm.obj.summary.runtime.powerState = "PoweredOn"
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_name",
            mock.Mock(return_value=vm)
        ):
            server.stop(server={"name": "server_name"},
                        os_family="other_os")
        vm.obj.PowerOff.assert_called_with()
Пример #4
0
    def test_server_resize_down(self):
        old_cpus = self.ctx.node.properties['server']['cpus']
        self.assertTrue(
            old_cpus > 1,
            "To test server shrink we need more than 1 cpu predefined")
        old_memory = self.ctx.node.properties['server']['memory']
        new_cpus = old_cpus - 1
        new_memory = old_memory - 64

        server_plugin.start()
        server = self.assert_server_exist_and_get(self.ctx.node.id)
        self.assertEqual(old_cpus, server.config.hardware.numCPU)
        self.assertEqual(old_memory, server.config.hardware.memoryMB)
        self.ctx.instance.runtime_properties['cpus'] = new_cpus
        self.ctx.instance.runtime_properties['memory'] = new_memory

        server_plugin.stop()

        server_plugin.resize()

        server = self.assert_server_exist_and_get(self.ctx.node.id)
        self.assertEqual(new_cpus, server.config.hardware.numCPU)
        self.assertEqual(new_memory, server.config.hardware.memoryMB)
    def test_stop(self, smart_m):
        conn_mock = mock.Mock()
        smart_m.return_value = conn_mock
        ctx = self._gen_ctx()

        # stop for external
        ctx.instance.runtime_properties['use_external_resource'] = True
        server.stop(server={"name": "server_name"},
                    os_family="other_os")

        # nosuch vm (we dont have vm_id)
        ctx.instance.runtime_properties['use_external_resource'] = False
        ctx.instance.runtime_properties['vsphere_server_id'] = None
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_id",
            mock.Mock(return_value=None)
        ):
            server.stop(server={"name": "server_name"},
                        os_family="other_os")

        # nosuch vm (we have vm_id)
        ctx.instance.runtime_properties['use_external_resource'] = False
        ctx.instance.runtime_properties['vsphere_server_id'] = 'vm-unknow'
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_id",
            mock.Mock(return_value=None)
        ):
            with self.assertRaisesRegexp(
                NonRecoverableError,
                "Cannot stop server - server doesn't exist for node: "
                "node_name"
            ):
                server.stop(server={"name": "server_name"},
                            os_family="other_os")

        # with poweredoff vm
        vm = mock.Mock()
        vm.obj.summary.runtime.powerState = "PoweredOFF"
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_id",
            mock.Mock(return_value=vm)
        ):
            server.stop(server={"name": "server_name"},
                        os_family="other_os")

        # with poweredoff vm
        vm = mock.Mock()
        task = mock.Mock()
        task.info.state = vim.TaskInfo.State.success
        vm.obj.snapshot = None  # no snapshots
        vm.obj.PowerOff = mock.Mock(return_value=task)
        vm.obj.summary.runtime.powerState = "PoweredOn"
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_id",
            mock.Mock(return_value=vm)
        ):
            server.stop(server={"name": "server_name"},
                        os_family="other_os")
        vm.obj.PowerOff.assert_called_with()

        # with poweredoff vm, use exteranl vm with force
        ctx.instance.runtime_properties['use_external_resource'] = True
        vm = mock.Mock()
        task = mock.Mock()
        task.info.state = vim.TaskInfo.State.success
        vm.obj.snapshot = None  # no snapshots
        vm.obj.PowerOff = mock.Mock(return_value=task)
        vm.obj.summary.runtime.powerState = "PoweredOn"
        with mock.patch(
            "vsphere_plugin_common.VsphereClient._get_obj_by_id",
            mock.Mock(return_value=vm)
        ):
            server.stop(server={"name": "server_name"},
                        os_family="other_os",
                        force_stop=True)
        vm.obj.PowerOff.assert_called_with()