Ejemplo n.º 1
0
    def create_one_image(self, user, **kwargs):
        """Create one image for the user."""

        clients = osclients.Clients(user["credential"])

        image_id = types.GlanceImage.transform(
            clients=clients, resource_config=self.config["image"])
        flavor_id = types.Flavor.transform(
            clients=clients, resource_config=self.config["flavor"])

        vm_scenario = vmtasks.BootRuncommandDelete(self.context,
                                                   clients=clients)

        server, fip = vm_scenario._boot_server_with_fip(
            image=image_id,
            flavor=flavor_id,
            floating_network=self.config.get("floating_network"),
            userdata=self.config.get("userdata"),
            key_name=user["keypair"]["name"],
            security_groups=[user["secgroup"]["name"]],
            **kwargs)

        try:
            LOG.debug("Installing tools on %r %s" % (server, fip["ip"]))
            self.customize_image(server, fip, user)

            LOG.debug("Stopping server %r" % server)
            vm_scenario._stop_server(server)

            LOG.debug("Creating snapshot for %r" % server)
            custom_image = vm_scenario._create_image(server)
        finally:
            vm_scenario._delete_server_with_fip(server, fip)

        return custom_image
Ejemplo n.º 2
0
    def test_boot_runcommand_delete_ping_wait_timeouts(self):
        scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))

        scenario._wait_for_ping.side_effect = exceptions.TimeoutException(
            resource_type="foo_resource",
            resource_name="foo_name",
            resource_id="foo_id",
            desired_status="foo_desired_status",
            resource_status="foo_resource_status",
            timeout=2)
        exc = self.assertRaises(exceptions.TimeoutException,
                                scenario.run,
                                "foo_image",
                                "foo_flavor",
                                "foo_interpreter",
                                "foo_script",
                                "foo_username",
                                wait_for_ping=True)
        self.assertEqual(exc.kwargs["resource_type"], "foo_resource")
        self.assertEqual(exc.kwargs["resource_name"], "foo_name")
        self.assertEqual(exc.kwargs["resource_id"], "foo_id")
        self.assertEqual(exc.kwargs["desired_status"], "foo_desired_status")
        self.assertEqual(exc.kwargs["resource_status"], "foo_resource_status")

        scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete=False)
        self.assertFalse(scenario.add_output.called)
Ejemplo n.º 3
0
    def test_boot_runcommand_delete_command_timeouts(self):
        scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))

        scenario._run_command.side_effect = exceptions.SSHTimeout()
        self.assertRaises(exceptions.SSHTimeout, scenario.run, "foo_flavor",
                          "foo_image", "foo_interpreter", "foo_script",
                          "foo_username")
        scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete=False)
        self.assertFalse(scenario.add_output.called)
Ejemplo n.º 4
0
    def test_boot_runcommand_delete_json_fails(self, mock_json):
        scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))

        mock_json.loads.side_effect = ValueError()
        scenario.run("foo_image", "foo_flavor", "foo_interpreter",
                     "foo_script", "foo_username")
        scenario.add_output.assert_called_once_with(
            complete={
                "chart_plugin": "TextArea",
                "data": ["StdErr: foo_err", "StdOut:", "{\"foo\": 42}"],
                "title": "Script Output"
            })
        scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete=False)
Ejemplo n.º 5
0
    def test_boot_runcommand_delete_add_output(self,
                                               output,
                                               expected=None,
                                               raises=None):
        scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))

        scenario._run_command.return_value = output
        kwargs = {
            "flavor": "foo_flavor",
            "image": "foo_image",
            "command": {
                "remote_path": "foo"
            },
            "username": "******",
            "password": "******",
            "use_floating_ip": "use_fip",
            "floating_network": "ext_network",
            "force_delete": "foo_force",
            "volume_args": {
                "size": 16
            },
            "foo_arg": "foo_value"
        }
        if raises:
            self.assertRaises(raises, scenario.run, **kwargs)
            self.assertFalse(scenario.add_output.called)
        else:
            scenario.run(**kwargs)
            calls = [mock.call(**kw) for kw in expected]
            scenario.add_output.assert_has_calls(calls, any_order=True)

            self.cinder.create_volume.assert_called_once_with(16,
                                                              imageRef=None)
            scenario._boot_server_with_fip.assert_called_once_with(
                "foo_image",
                "foo_flavor",
                key_name="keypair_name",
                use_floating_ip="use_fip",
                floating_network="ext_network",
                block_device_mapping={"vdrally": "foo_volume:::1"},
                foo_arg="foo_value")

            scenario._run_command.assert_called_once_with(
                "foo_ip",
                22,
                "foo_username",
                "foo_password",
                command={"remote_path": "foo"})
            scenario._delete_server_with_fip.assert_called_once_with(
                "foo_server", self.ip, force_delete="foo_force")
Ejemplo n.º 6
0
    def test_boot_runcommand_delete(self):
        scenario = self.create_env(vmtasks.BootRuncommandDelete(self.context))
        scenario._run_command = mock.MagicMock(return_value=(0,
                                                             "{\"foo\": 42}",
                                                             "foo_err"))
        scenario.run("foo_flavor",
                     image="foo_image",
                     command={
                         "script_file": "foo_script",
                         "interpreter": "foo_interpreter"
                     },
                     username="******",
                     password="******",
                     use_floating_ip="use_fip",
                     floating_network="ext_network",
                     force_delete="foo_force",
                     volume_args={"size": 16},
                     foo_arg="foo_value")

        self.cinder.create_volume.assert_called_once_with(16, imageRef=None)
        scenario._boot_server_with_fip.assert_called_once_with(
            "foo_image",
            "foo_flavor",
            key_name="keypair_name",
            use_floating_ip="use_fip",
            floating_network="ext_network",
            block_device_mapping={"vdrally": "foo_volume:::1"},
            foo_arg="foo_value")

        scenario._wait_for_ping.assert_called_once_with("foo_ip")
        scenario._run_command.assert_called_once_with("foo_ip",
                                                      22,
                                                      "foo_username",
                                                      "foo_password",
                                                      command={
                                                          "script_file":
                                                          "foo_script",
                                                          "interpreter":
                                                          "foo_interpreter"
                                                      })
        scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete="foo_force")
        scenario.add_output.assert_called_once_with(
            complete={
                "chart_plugin": "TextArea",
                "data": ["StdErr: foo_err", "StdOut:", "{\"foo\": 42}"],
                "title": "Script Output"
            })