class TestShowCluster(fakes.TestCCE):

    _obj = fakes.FakeCluster.create_one()

    columns = ('ID', 'name', 'type', 'status', 'version', 'endpoint',
               'flavor', 'router_id', 'network_id')
    flat_data = cluster._flatten_cluster(_obj)
    data = (
        flat_data['id'],
        flat_data['name'],
        flat_data['type'],
        flat_data['status'],
        flat_data['version'],
        flat_data['endpoint'],
        flat_data['flavor'],
        flat_data['router_id'],
        flat_data['network_id'],
    )

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

        self.cmd = cluster.ShowCCECluster(self.app, None)

        self.client.find_cluster = mock.Mock()

    def test_get(self):
        arglist = [
            'cluster_uuid'
        ]

        verifylist = [
            ('cluster', 'cluster_uuid')
        ]

        # Verify cm is triggereg with default parameters
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Set the response
        self.client.find_cluster.side_effect = [
            self._obj
        ]

        # Trigger the action
        columns, data = self.cmd.take_action(parsed_args)

        self.client.find_cluster.assert_called_once_with('cluster_uuid')

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, data)
class TestListCluster(fakes.TestCCE):

    _objs = fakes.FakeCluster.create_multiple(3)

    columns = ('ID', 'name', 'status', 'flavor', 'version', 'endpoint')

    data = []

    for s in _objs:
        flat_data = cluster._flatten_cluster(s)
        data.append((
            flat_data['id'],
            flat_data['name'],
            flat_data['status'],
            flat_data['flavor'],
            flat_data['version'],
            flat_data['endpoint'],
        ))

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

        self.cmd = cluster.ListCCECluster(self.app, None)

        self.client.clusters = mock.Mock()

    def test_list_default(self):
        arglist = []

        verifylist = []

        # Verify cm is triggereg with default parameters
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Set the response
        self.client.clusters.side_effect = [
            self._objs
        ]

        # Trigger the action
        columns, data = self.cmd.take_action(parsed_args)

        self.client.clusters.assert_called_once_with()

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, list(data))
Exemplo n.º 3
0
    def test_flatten(self):
        _obj = fakes.FakeCluster.create_one()

        flat_data = cluster._flatten_cluster(_obj)

        data = (
            flat_data['id'],
            flat_data['name'],
            flat_data['endpoint'],
            flat_data['status'],
            flat_data['version'],
            flat_data['type'],
        )

        cmp_data = (_obj.metadata.id, _obj.metadata.name,
                    _obj.status.endpoints['external_otc'], _obj.status.status,
                    _obj.spec.version, _obj.spec.type)

        self.assertEqual(data, cmp_data)
class TestCreateCluster(fakes.TestCCE):

    _obj = fakes.FakeCluster.create_one()

    columns = ('ID', 'name', 'version', 'endpoint')

    flat_data = cluster._flatten_cluster(_obj)
    data = (
        flat_data['id'],
        flat_data['name'],
        flat_data['version'],
        flat_data['endpoint'],
    )

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

        self.cmd = cluster.CreateCCECluster(self.app, None)

        self.client.create_cluster = mock.Mock()
        self.client.get_cluster = mock.Mock()
        self.client.wait_for_job = mock.Mock()

    def test_create(self):
        arglist = [
            'cluster_name',
            'vpc_id',
            'net_id',
            '--description', 'descr',
            '--type', 'VirtualMachine',
            '--flavor', 'flavor',
            '--container-net-mode', 'overlay_l2'
        ]

        verifylist = [
            ('name', 'cluster_name'),
            ('router_id', 'vpc_id'),
            ('network_id', 'net_id'),
            ('description', 'descr'),
            ('type', 'VirtualMachine'),
            ('flavor', 'flavor'),
            ('container_net_mode', 'overlay_l2')
        ]

        # Verify cm is triggereg with default parameters
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Set the response
        self.client.create_cluster.side_effect = [
            self._obj
        ]

        # Trigger the action
        columns, data = self.cmd.take_action(parsed_args)

        self.client.create_cluster.assert_called_once_with(
            name='cluster_name',
            spec={
                'type': 'VirtualMachine',
                'flavor': 'flavor',
                'description': 'descr',
                'hostNetwork': {
                    'router_id': 'vpc_id',
                    'network_id': 'net_id'
                },
                'containerNetwork': {
                    'mode': 'overlay_l2'
                }
            }
        )

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, data)

    def test_wait(self):
        arglist = [
            'cluster_name',
            'vpc_id',
            'net_id',
            '--description', 'descr',
            '--type', 'VirtualMachine',
            '--flavor', 'flavor',
            '--container-net-mode', 'overlay_l2',
            '--wait',
            '--wait-interval', '13'
        ]

        verifylist = [
            ('name', 'cluster_name'),
            ('router_id', 'vpc_id'),
            ('network_id', 'net_id'),
            ('description', 'descr'),
            ('type', 'VirtualMachine'),
            ('flavor', 'flavor'),
            ('container_net_mode', 'overlay_l2'),
            ('wait', True),
            ('wait_interval', 13)
        ]

        # Verify cm is triggereg with default parameters
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Set the response
        self.client.create_cluster.side_effect = [
            self._obj
        ]

        self.client.get_cluster.side_effect = [self._obj]

        # Trigger the action
        columns, data = self.cmd.take_action(parsed_args)

        self.client.create_cluster.assert_called_once_with(
            name='cluster_name',
            spec={
                'type': 'VirtualMachine',
                'flavor': 'flavor',
                'description': 'descr',
                'hostNetwork': {
                    'router_id': 'vpc_id',
                    'network_id': 'net_id'
                },
                'containerNetwork': {
                    'mode': 'overlay_l2'
                }
            }
        )

        self.client.wait_for_job.assert_called_with(
            self._obj.job_id,
            interval=13)

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, data)
Exemplo n.º 5
0
class TestClusterCreate(fakes.TestCCE):

    _obj = fakes.FakeCluster.create_one()

    columns = ('ID', 'name', 'version', 'endpoint')

    flat_data = cluster._flatten_cluster(_obj)
    data = (
        flat_data['id'],
        flat_data['name'],
        flat_data['version'],
        flat_data['endpoint'],
    )

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

        self.cmd = cluster.CreateCCECluster(self.app, None)

        self.sdk_client.create_cce_cluster = \
            mock.Mock(return_value=self._obj)

    def test_create(self):
        arglist = [
            'cluster_name', 'vpc_id', 'net_id', '--description', 'descr',
            '--type', 'VirtualMachine', '--flavor', 'flavor',
            '--container-network-mode', 'overlay_l2'
        ]

        verifylist = [('name', 'cluster_name'), ('router', 'vpc_id'),
                      ('network', 'net_id'), ('description', 'descr'),
                      ('type', 'VirtualMachine'), ('flavor', 'flavor'),
                      ('container_network_mode', 'overlay_l2')]

        # Verify cm is triggereg with default parameters
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Trigger the action
        columns, data = self.cmd.take_action(parsed_args)

        self.sdk_client.create_cce_cluster.assert_called_once_with(
            container_network_mode='overlay_l2',
            description='descr',
            flavor='flavor',
            name='cluster_name',
            network='net_id',
            router='vpc_id',
            type='VirtualMachine',
            wait=False)

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, data)

    def test_wait(self):
        arglist = [
            'cluster_name', 'vpc_id', 'net_id', '--description', 'descr',
            '--type', 'VirtualMachine', '--flavor', 'flavor',
            '--container-network-mode', 'overlay_l2', '--wait',
            '--wait-interval', '13'
        ]

        verifylist = [('name', 'cluster_name'), ('router', 'vpc_id'),
                      ('network', 'net_id'), ('description', 'descr'),
                      ('type', 'VirtualMachine'), ('flavor', 'flavor'),
                      ('container_network_mode', 'overlay_l2'), ('wait', True),
                      ('wait_interval', 13)]

        # Verify cm is triggereg with default parameters
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Trigger the action
        columns, data = self.cmd.take_action(parsed_args)

        self.sdk_client.create_cce_cluster.assert_called_once_with(
            container_network_mode='overlay_l2',
            description='descr',
            flavor='flavor',
            name='cluster_name',
            network='net_id',
            router='vpc_id',
            type='VirtualMachine',
            wait=True,
            wait_interval=13)

        self.assertEqual(self.columns, columns)
        self.assertEqual(self.data, data)