Exemple #1
0
 def setUp(self):
     super(DestroyEnvironmentTest, self).setUp()
     self.cmd = DestroyEnvironment(self.config, self.provider, self.env)
Exemple #2
0
 def setUp(self):
     super(DestroyEnvironmentTest, self).setUp()
     self.cmd = DestroyEnvironment(self.config, self.provider, self.env)
Exemple #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 = [
            Linode_instace.from_dict(
                dict(id=220, name="linodeabc", ip_address="10.0.1.19")),
            Linode_instace.from_dict(
                dict(id=221, name="linode-123123", ip_address="10.0.1.23")),
            Linode_instace.from_dict(
                dict(id=258, name="linode-209123", ip_address="10.0.1.25")),
            Linode_instace.from_dict(
                dict(id=233, name="mary", ip_address="10.0.1.32")),
            Linode_instace.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_linode.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 = [
            Linode_instace.from_dict(
                dict(id=221, name="linode-123123", ip_address="10.0.1.23")),
            Linode_instace.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_linode.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 = [
            Linode_instace.from_dict(
                dict(id=221, name="linode-123123", ip_address="10.0.1.23")),
            Linode_instace.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'])])
Exemple #4
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 = [
            Linode_instace.from_dict(dict(
                id=220, name="linodeabc", ip_address="10.0.1.19")),
            Linode_instace.from_dict(dict(
                id=221, name="linode-123123", ip_address="10.0.1.23")),
            Linode_instace.from_dict(dict(
                id=258, name="linode-209123", ip_address="10.0.1.25")),
            Linode_instace.from_dict(dict(
                id=233, name="mary", ip_address="10.0.1.32")),
            Linode_instace.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_linode.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 = [
            Linode_instace.from_dict(dict(
                id=221, name="linode-123123", ip_address="10.0.1.23")),
            Linode_instace.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_linode.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 = [
            Linode_instace.from_dict(dict(
                id=221, name="linode-123123", ip_address="10.0.1.23")),
            Linode_instace.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'])])