def setUp(self):
        super(TestNodeCommand, self).setUp()

        self.m_client.get_all.return_value = [
            fake_node.get_fake_node() for i in range(10)
        ]
        self.m_client.get_by_id.return_value = fake_node.get_fake_node()
Beispiel #2
0
    def test_node_list_ansible_inventory(self):
        self.m_client.get_all.return_value = [
            fake_node.get_fake_node(hostname='node-1',
                                    ip='10.20.0.2',
                                    roles=['compute']),
            fake_node.get_fake_node(hostname='node-2',
                                    ip='10.20.0.3',
                                    roles=['compute', 'ceph-osd']),
            fake_node.get_fake_node(hostname='node-3',
                                    ip='10.20.0.4',
                                    roles=['controller']),
            fake_node.get_fake_node(hostname='node-4',
                                    ip='10.20.0.5',
                                    roles=['controller', 'mongo']),
            fake_node.get_fake_node(hostname='node-5',
                                    ip='10.20.0.6',
                                    roles=['controller', 'ceph-osd']),
        ]

        expected_output = '''\
[ceph-osd]
node-2 ansible_host=10.20.0.3
node-5 ansible_host=10.20.0.6

[compute]
node-1 ansible_host=10.20.0.2
node-2 ansible_host=10.20.0.3

[controller]
node-3 ansible_host=10.20.0.4
node-4 ansible_host=10.20.0.5
node-5 ansible_host=10.20.0.6

[mongo]
node-4 ansible_host=10.20.0.5

'''

        args = 'node ansible-inventory --env 1'
        with mock.patch('sys.stdout', new=io.StringIO()) as mstdout:
            rv = self.exec_command(args)
            actual_output = mstdout.getvalue()

        self.assertFalse(rv)
        self.assertEqual(expected_output, actual_output)

        self.m_get_client.assert_called_once_with('node', mock.ANY)
        self.m_client.get_all.assert_called_once_with(
            environment_id=1, labels=None)
Beispiel #3
0
    def test_node_set_name(self, m_emit_one):
        self.m_client._updatable_attributes = \
            node.NodeClient._updatable_attributes
        node_id = 37
        expected_field_data = cmd_node.NodeShow.columns

        test_cases = ('new-name', 'New Name', 'śćż∑ Pó', '你一定是无聊')
        for name in test_cases:
            self.m_client.update.return_value = fake_node.get_fake_node(
                node_id=node_id, node_name=name)

            cmd = ['node', 'update', str(node_id), '--name', name]

            # NOTE(sbrzeczkowski): due to shlex inability to accept
            # unicode arguments prior to python 2.7.3
            main_mod.main(argv=cmd)

            if six.PY2:
                name = name.decode('utf-8')

            m_emit_one.assert_called_with(expected_field_data,
                                          mock.ANY,
                                          mock.ANY,
                                          mock.ANY)
            self.m_get_client.assert_called_once_with('node', mock.ANY)
            self.m_client.update.assert_called_once_with(
                node_id, name=name)
            self.m_get_client.reset_mock()
            self.m_client.reset_mock()
    def setUp(self):
        super(TestNodeExecuteTasksAction, self).setUp()
        self.tasks = ['netconfig', 'hiera', 'install']

        node_patch = patch('fuelclient.objects.node.Node.get_fresh_data')
        m_fresh_data = node_patch.start()
        m_fresh_data.return_value = fake_node.get_fake_node()
        self.addCleanup(node_patch.stop)
Beispiel #5
0
    def setUp(self):
        super(TestNodeExecuteTasksAction, self).setUp()
        self.tasks = ['netconfig', 'hiera', 'install']

        node_patch = patch('fuelclient.objects.node.Node.get_fresh_data')
        m_fresh_data = node_patch.start()
        m_fresh_data.return_value = fake_node.get_fake_node()
        self.addCleanup(node_patch.stop)
    def test_node_set_hostname(self):
        self.m_client._updatable_attributes = \
            node.NodeClient._updatable_attributes
        node_id = 42
        hostname = 'test-name'

        self.m_client.update.return_value = \
            fake_node.get_fake_node(node_id=node_id,
                                    hostname=hostname)

        args = 'node update {node_id} --hostname {hostname}'\
            .format(node_id=node_id, hostname=hostname)

        self.exec_command(args)

        self.m_get_client.assert_called_once_with('node', mock.ANY)
        self.m_client.update.assert_called_once_with(node_id,
                                                     hostname=hostname)
    def test_node_set_hostname(self):
        self.m_client._updatable_attributes = \
            node.NodeClient._updatable_attributes
        node_id = 42
        hostname = 'test-name'

        self.m_client.update.return_value = \
            fake_node.get_fake_node(node_id=node_id,
                                    hostname=hostname)

        args = 'node update {node_id} --hostname {hostname}'\
            .format(node_id=node_id, hostname=hostname)

        self.exec_command(args)

        self.m_get_client.assert_called_once_with('node', mock.ANY)
        self.m_client.update.assert_called_once_with(
            node_id, hostname=hostname)
Beispiel #8
0
    def test_node_set_hostname(self, m_emit_one):
        self.m_client._updatable_attributes = \
            node.NodeClient._updatable_attributes
        node_id = 42
        hostname = 'test-name'
        expected_field_data = cmd_node.NodeShow.columns

        self.m_client.update.return_value = \
            fake_node.get_fake_node(node_id=node_id,
                                    hostname=hostname)

        args = 'node update {node_id} --hostname {hostname}'\
            .format(node_id=node_id, hostname=hostname)

        self.exec_command(args)
        m_emit_one.assert_called_once_with(expected_field_data, mock.ANY,
                                           mock.ANY, mock.ANY)

        self.m_get_client.assert_called_once_with('node', mock.ANY)
        self.m_client.update.assert_called_once_with(node_id,
                                                     hostname=hostname)
    def test_node_set_hostname(self, m_emit_one):
        self.m_client._updatable_attributes = \
            node.NodeClient._updatable_attributes
        node_id = 42
        hostname = 'test-name'
        expected_field_data = cmd_node.NodeShow.columns

        self.m_client.update.return_value = \
            fake_node.get_fake_node(node_id=node_id,
                                    hostname=hostname)

        args = 'node update {node_id} --hostname {hostname}'\
            .format(node_id=node_id, hostname=hostname)

        self.exec_command(args)
        m_emit_one.assert_called_once_with(expected_field_data,
                                           mock.ANY,
                                           mock.ANY,
                                           mock.ANY)

        self.m_get_client.assert_called_once_with('node', mock.ANY)
        self.m_client.update.assert_called_once_with(
            node_id, hostname=hostname)
Beispiel #10
0
    def setUp(self):
        super(TestNodeCommand, self).setUp()

        self.m_client.get_all.return_value = [fake_node.get_fake_node()
                                              for i in range(10)]
        self.m_client.get_by_id.return_value = fake_node.get_fake_node()