Пример #1
0
 def test_delete_old_machines(self):
     machine = make_machine('stopped')
     client = Client('sdc_url',
                     'account',
                     'key_id',
                     './key',
                     'manta_url',
                     pause=0)
     with patch.object(client,
                       '_list_machines',
                       side_effect=fake_list_machines(machine)) as lm_mock:
         with patch.object(client,
                           '_list_machine_tags',
                           autospec=True,
                           return_value={}) as lmt_mock:
             with patch.object(client,
                               '_delete_running_machine',
                               autospec=True) as drm_mock:
                 with patch.object(client,
                                   'attempt_deletion',
                                   autospec=True) as rd_mock:
                     client.delete_old_machines(1)
     lm_mock.assert_called_once_with()
     lmt_mock.assert_called_once_with('id')
     drm_mock.assert_called_once_with('id')
     self.assertEqual(0, rd_mock.call_count)
Пример #2
0
 def test_list_machine_tags(self):
     client = Client(
         'sdc_url', 'account', 'key_id', './key', 'manta_url', pause=0)
     headers = {}
     content = json.dumps({'env': 'foo'})
     with patch.object(client, '_request', autospec=True,
                       return_value=(headers, content)) as mock:
         tags = client._list_machine_tags('bar')
     mock.assert_called_once_with('/machines/bar/tags')
     self.assertEqual({'env': 'foo'}, tags)
Пример #3
0
 def test_delete_old_machines_stuck_provisioning(self):
     machine = make_machine('provisioning')
     client = Client(
         'sdc_url', 'account', 'key_id', 'manta_url', './key', pause=0)
     with patch.object(client, '_list_machines', autospec=True,
                       side_effect=fake_list_machines(machine)):
         with patch.object(client, '_list_machine_tags', autospec=True):
             with patch.object(client, '_delete_running_machine',
                               autospec=True) as drm_mock:
                 with patch.object(client, 'request_deletion',
                                   autospec=True) as rd_mock:
                     client.delete_old_machines(1, 'foo@bar')
     self.assertEqual(0, drm_mock.call_count)
     rd_mock.assert_called_once_with([machine], 'foo@bar')
Пример #4
0
 def test_attempt_deletion(self):
     client = Client(
         'sdc_url', 'account', 'key_id', './key', 'manta_url', pause=0)
     with patch.object(client, 'delete_machine', autospec=True) as dm_func:
         all_success = client.attempt_deletion(['a', 'b'])
     self.assertIs(True, all_success)
     dm_func.assert_any_call('a')
     dm_func.assert_any_call('b')
     with patch.object(client, 'delete_machine', autospec=True,
                       side_effect=[Exception, None]) as dm_func:
         all_success = client.attempt_deletion(['a', 'b'])
     self.assertIs(False, all_success)
     dm_func.assert_any_call('a')
     dm_func.assert_any_call('b')
Пример #5
0
 def test_delete_old_machines_permanent(self):
     machine = make_machine('provisioning')
     client = Client(
         'sdc_url', 'account', 'key_id', './key', 'manta_url', pause=0)
     with patch.object(client, '_list_machines', autospec=True,
                       side_effect=fake_list_machines(machine)):
         with patch.object(client, '_list_machine_tags', autospec=True,
                           return_value={'permanent': 'true'}) as lmt_mock:
             with patch.object(client, '_delete_running_machine',
                               autospec=True) as drm_mock:
                 with patch.object(client, 'attempt_deletion',
                                   autospec=True) as rd_mock:
                     client.delete_old_machines(1)
     lmt_mock.assert_called_once_with('id')
     self.assertEqual(0, drm_mock.call_count)
     self.assertEqual(0, rd_mock.call_count)
Пример #6
0
 def test_delete_old_machines(self):
     machine = make_machine('stopped')
     client = Client(
         'sdc_url', 'account', 'key_id', './key', 'manta_url', pause=0)
     with patch.object(client, '_list_machines',
                       side_effect=[[machine], [machine]]) as lm_mock:
         with patch.object(client, '_list_machine_tags', autospec=True,
                           return_value={}) as lmt_mock:
             with patch.object(client, '_delete_running_machine',
                               autospec=True) as drm_mock:
                 with patch.object(client, 'request_deletion',
                                   autospec=True) as rd_mock:
                     client.delete_old_machines(1, 'foo@bar')
     lm_mock.assert_called_once_with()
     lmt_mock.assert_called_once_with('id')
     drm_mock.assert_called_once_with('id')
     self.assertEqual(0, rd_mock.call_count)
Пример #7
0
 def test_init(self):
     client = Client(
         'sdc_url', 'account', 'key_id', './key', 'manta_url',
         dry_run=True, verbose=True)
     self.assertEqual('sdc_url', client.sdc_url)
     self.assertEqual('account', client.account)
     self.assertEqual('key_id', client.key_id)
     self.assertEqual('./key', client.key_path)
     self.assertEqual(3, client.pause)
     self.assertTrue(client.dry_run)
     self.assertTrue(client.verbose)
Пример #8
0
 def test_attempt_deletion(self):
     client = Client('sdc_url',
                     'account',
                     'key_id',
                     './key',
                     'manta_url',
                     pause=0)
     with patch.object(client, 'delete_machine', autospec=True) as dm_func:
         all_success = client.attempt_deletion(['a', 'b'])
     self.assertIs(True, all_success)
     dm_func.assert_any_call('a')
     dm_func.assert_any_call('b')
     with patch.object(client,
                       'delete_machine',
                       autospec=True,
                       side_effect=[Exception, None]) as dm_func:
         all_success = client.attempt_deletion(['a', 'b'])
     self.assertIs(False, all_success)
     dm_func.assert_any_call('a')
     dm_func.assert_any_call('b')
Пример #9
0
    def from_boot_config(cls, boot_config):
        """Create a ContextManager for a JoyentAccount.

         Using a SimpleEnvironment or JujuData, the private key is written to
         a tmp file. Then, the Joyent client is inited with the path to the
         tmp key. The key is removed when done.
         """
        from joyent import Client
        config = get_config(boot_config)
        with temp_dir() as key_dir:
            key_path = os.path.join(key_dir, 'joyent.key')
            open(key_path, 'w').write(config['private-key'])
            client = Client(config['sdc-url'], config['manta-user'],
                            config['manta-key-id'], key_path, '')
            yield cls(client)