Ejemplo n.º 1
0
class DestroyEnvironmentTest(CommandBase):

    def setUp(self):
        super(DestroyEnvironmentTest, self).setUp()
        self.cmd = DestroyEnvironment(self.config, self.provider, self.env)

    @mock.patch('juju_docean.commands.time')
    def test_destroy_environment(self, mock_time):
        self.setup_env()
        self.env.status.return_value = {
            'machines': {
                '0': {
                    'dns-name': '10.0.1.23',
                    'instance-id': 'manual:ip_address'},
                '1': {
                    'dns-name': '10.0.1.25',
                    'instance-id': 'manual:ip_address'}
            }}
        self.provider.get_instances.return_value = [
            Droplet.from_dict(dict(
                id=221, name="docean-123123", ip_address="10.0.1.23")),
            Droplet.from_dict(dict(
                id=258, name="docena-209123", ip_address="10.0.1.25"))]

        # Destroy Env has a sleep / mock it out.
        mock_time.sleep.return_value = None
        self.cmd.run()
        self.assertEqual(
            self.provider.terminate_instance.call_args_list,
            [mock.call(258), mock.call(221)])
        self.env.terminate_machines.assert_called_once_with(['1'])
Ejemplo n.º 2
0
 def setUp(self):
     super(DestroyEnvironmentTest, self).setUp()
     self.cmd = DestroyEnvironment(self.config, self.provider, self.env)
Ejemplo n.º 3
0
class DestroyEnvironmentTest(CommandBase):
    def setUp(self):
        super(DestroyEnvironmentTest, self).setUp()
        self.cmd = DestroyEnvironment(self.config, self.provider, self.env)

    def test_destroy_environment_force(self):
        self.config.options.force = True
        self.setup_env()
        self.provider.get_instances.return_value = [
            Droplet.from_dict(dict(id=220, name="doceanabc", ip_address="10.0.1.19")),
            Droplet.from_dict(dict(id=221, name="docean-123123", ip_address="10.0.1.23")),
            Droplet.from_dict(dict(id=258, name="docean-209123", ip_address="10.0.1.25")),
            Droplet.from_dict(dict(id=233, name="mary", ip_address="10.0.1.32")),
            Droplet.from_dict(dict(id=234, name="loug", ip_address="10.0.1.18")),
        ]

        self.cmd.run()
        self.assertEqual(self.provider.terminate_instance.call_args_list, [mock.call(221), mock.call(258)])
        self.env.destroy_environment_jenv.assert_called_once()

    @mock.patch("juju_docean.commands.time")
    def test_destroy_environment(self, mock_time):
        self.config.options.force = False
        self.setup_env()
        self.env.status.return_value = {
            "machines": {
                "0": {"dns-name": "10.0.1.23", "instance-id": "manual:ip_address"},
                "1": {"dns-name": "10.0.1.25", "instance-id": "manual:ip_address"},
            }
        }
        self.provider.get_instances.return_value = [
            Droplet.from_dict(dict(id=221, name="docean-123123", ip_address="10.0.1.23")),
            Droplet.from_dict(dict(id=258, name="docena-209123", ip_address="10.0.1.25")),
        ]

        # Destroy Env has a sleep / mock it out.
        mock_time.sleep.return_value = None
        self.cmd.run()
        self.assertEqual(self.provider.terminate_instance.call_args_list, [mock.call(258), mock.call(221)])
        self.env.terminate_machines.assert_called_once_with(["1"])

    @mock.patch("juju_docean.commands.time")
    def test_destroy_environment_with_missing_iaas_machine(self, mock_time):
        self.config.options.force = False
        self.setup_env()
        self.env.status.return_value = {
            "machines": {
                "0": {"dns-name": "10.0.1.23", "instance-id": "manual:ip_address"},
                "1": {"dns-name": "10.0.1.25", "instance-id": "manual:ip_address"},
                "2": {"dns-name": "10.0.1.27", "instance-id": "manual:ip_address"},
            }
        }
        self.provider.get_instances.return_value = [
            Droplet.from_dict(dict(id=221, name="docean-123123", ip_address="10.0.1.23")),
            Droplet.from_dict(dict(id=258, name="docena-209123", ip_address="10.0.1.25")),
        ]

        # Destroy Env has a sleep / mock it out.
        mock_time.sleep.return_value = None
        self.cmd.run()
        self.assertEqual(self.provider.terminate_instance.call_args_list, [mock.call(258), mock.call(221)])
        self.assertEqual(self.env.terminate_machines.call_args_list, [mock.call(["1"]), mock.call(["2"])])