Ejemplo n.º 1
0
    def test_show_table(self, mock_os_conf, mock_pr):
        mock_pr.return_value.show_instances.return_value = self.instances
        args = ['show', 'uuid1', 'hostname2']
        _cmd.main(args)

        mock_pr.return_value.show_instances.assert_called_once_with(
            ['uuid1', 'hostname2'])
Ejemplo n.º 2
0
    def test_list_table_empty(self, mock_os_conf, mock_pr):
        mock_pr.return_value.list_instances.return_value = []
        args = ['list']
        _cmd.main(args)

        self.mock_print.assert_called_once_with('')
        mock_pr.return_value.list_instances.assert_called_once_with()
Ejemplo n.º 3
0
    def test_list_empty(self, mock_os_conf, mock_pr):
        mock_pr.return_value.list_instances.return_value = []
        args = ['--format', 'value', 'list']
        _cmd.main(args)

        self.assertFalse(self.mock_print.called)
        mock_pr.return_value.list_instances.assert_called_once_with()
Ejemplo n.º 4
0
 def test_dry_run(self, mock_os_conf, mock_pr):
     args = ['--dry-run', 'undeploy', '123456']
     _cmd.main(args)
     mock_pr.assert_called_once_with(
         cloud_region=mock_os_conf.return_value.get_one.return_value,
         dry_run=True)
     mock_pr.return_value.unprovision_node.assert_called_once_with(
         '123456', wait=None)
Ejemplo n.º 5
0
    def test_list_one_column(self, mock_os_conf, mock_pr):
        mock_pr.return_value.list_instances.return_value = self.instances
        args = ['--format', 'value', '--column', 'Node Name', 'list']
        _cmd.main(args)

        self.mock_print.assert_has_calls([
            mock.call('name-1'),
            mock.call('name-2'),
        ])
        mock_pr.return_value.list_instances.assert_called_once_with()
Ejemplo n.º 6
0
    def test_list_sort(self, mock_os_conf, mock_pr):
        mock_pr.return_value.list_instances.return_value = self.instances
        args = ['--format', 'value', '--sort-column', 'IP Addresses', 'list']
        _cmd.main(args)

        self.mock_print.assert_has_calls([
            mock.call('2 name-2  hostname2 DEPLOYING '),
            mock.call('1 name-1 100 hostname1 ACTIVE private=1.2.3.4'),
        ])
        mock_pr.return_value.list_instances.assert_called_once_with()
Ejemplo n.º 7
0
    def test_quiet(self, mock_os_conf, mock_pr):
        args = ['--quiet', 'undeploy', '123456']
        _cmd.main(args)

        mock_pr.assert_called_once_with(
            cloud_region=mock_os_conf.return_value.get_one.return_value,
            dry_run=False)
        mock_pr.return_value.unprovision_node.assert_called_once_with(
            '123456', wait=None)
        self.assertFalse(self.mock_print.called)
Ejemplo n.º 8
0
    def test_show(self, mock_os_conf, mock_pr):
        mock_pr.return_value.show_instances.return_value = self.instances
        args = ['--format', 'value', 'show', 'uuid1', 'hostname2']
        _cmd.main(args)

        self.mock_print.assert_has_calls([
            mock.call('1 name-1 100 hostname1 ACTIVE private=1.2.3.4'),
            mock.call('2 name-2  hostname2 DEPLOYING '),
        ])
        mock_pr.return_value.show_instances.assert_called_once_with(
            ['uuid1', 'hostname2'])
Ejemplo n.º 9
0
    def test_wait(self, mock_os_conf, mock_pr):
        mock_pr.return_value.wait_for_provisioning.return_value = (
            self.instances)
        args = ['--format', 'value', 'wait', 'uuid1', 'hostname2']
        _cmd.main(args)

        self.mock_print.assert_has_calls([
            mock.call('1 name-1 100 hostname1 ACTIVE private=1.2.3.4'),
            mock.call('2 name-2  hostname2 DEPLOYING '),
        ])
        mock_pr.return_value.wait_for_provisioning.assert_called_once_with(
            ['uuid1', 'hostname2'], timeout=None)
Ejemplo n.º 10
0
    def test_show_json(self, mock_os_conf, mock_pr):
        mock_pr.return_value.show_instances.return_value = self.instances
        args = ['--format', 'json', 'show', 'uuid1', 'hostname2']

        fake_io = io.StringIO()
        with mock.patch('sys.stdout', fake_io):
            _cmd.main(args)
            self.assertEqual(json.loads(fake_io.getvalue()), {
                'hostname1': {
                    '1': 'name-1'
                },
                'hostname2': {
                    '2': 'name-2'
                }
            })
Ejemplo n.º 11
0
    def test_custom_wait(self, mock_os_conf, mock_pr):
        node = mock_pr.return_value.unprovision_node.return_value
        node.id = '123'
        node.name = None
        node.provision_state = 'available'

        args = ['undeploy', '--wait', '1800', '123456']
        _cmd.main(args)
        mock_pr.assert_called_once_with(
            cloud_region=mock_os_conf.return_value.get_one.return_value,
            dry_run=False)
        mock_pr.return_value.unprovision_node.assert_called_once_with(
            '123456', wait=1800)
        self.mock_print.assert_called_once_with(
            'Successfully unprovisioned node %(node)s', node='123')
Ejemplo n.º 12
0
    def test_ok(self, mock_os_conf, mock_pr):
        node = mock_pr.return_value.unprovision_node.return_value
        node.id = '123'
        node.name = None
        node.provision_state = 'cleaning'

        args = ['undeploy', '123456']
        _cmd.main(args)

        mock_pr.assert_called_once_with(
            cloud_region=mock_os_conf.return_value.get_one.return_value,
            dry_run=False)
        mock_pr.return_value.unprovision_node.assert_called_once_with(
            '123456', wait=None)
        self.mock_print.assert_called_once_with(
            'Unprovisioning started for node %(node)s', node='123')
Ejemplo n.º 13
0
    def test_json(self, mock_os_conf, mock_pr):
        node = mock_pr.return_value.unprovision_node.return_value
        node.to_dict.return_value = {'node': 'dict'}

        args = ['--format', 'json', 'undeploy', '123456']
        fake_io = io.StringIO()
        with mock.patch('sys.stdout', fake_io):
            _cmd.main(args)
            self.assertEqual(json.loads(fake_io.getvalue()),
                             {'node': {
                                 'node': 'dict'
                             }})

        mock_pr.assert_called_once_with(
            cloud_region=mock_os_conf.return_value.get_one.return_value,
            dry_run=False)
        mock_pr.return_value.unprovision_node.assert_called_once_with(
            '123456', wait=None)
Ejemplo n.º 14
0
    def _check(self,
               mock_pr,
               args,
               reserve_args,
               provision_args,
               dry_run=False,
               formatter='value'):
        reserve_defaults = dict(resource_class='compute',
                                conductor_group=None,
                                capabilities={},
                                traits=[],
                                candidates=None,
                                hostname=None)
        reserve_defaults.update(reserve_args)

        provision_defaults = dict(image=mock.ANY,
                                  nics=[{
                                      'network': 'mynet'
                                  }],
                                  root_size_gb=None,
                                  swap_size_mb=None,
                                  config=mock.ANY,
                                  netboot=False,
                                  wait=1800,
                                  clean_up_on_failure=True)
        provision_defaults.update(provision_args)

        if not self._init:
            self._init_instance(mock_pr)

        if '--format' not in args and formatter:
            args = ['--format', formatter] + args
        _cmd.main(args)

        mock_pr.assert_called_once_with(
            cloud_region=self.mock_os_conf.return_value.get_one.return_value,
            dry_run=dry_run)
        mock_pr.return_value.reserve_node.assert_called_once_with(
            **reserve_defaults)
        mock_pr.return_value.provision_node.assert_called_once_with(
            mock_pr.return_value.reserve_node.return_value,
            **provision_defaults)
Ejemplo n.º 15
0
    def test_list_table(self, mock_os_conf, mock_pr):
        mock_pr.return_value.list_instances.return_value = self.instances
        args = ['list']
        _cmd.main(args)

        mock_pr.return_value.list_instances.assert_called_once_with()