Пример #1
0
    def test_pool_create(self):
        form_data = {
            'name': 'pool1name',
            'description': 'pool1description',
            'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
            'protocol': 'HTTP',
            'lb_method': 'ROUND_ROBIN',
            'admin_state_up': True
        }

        pool = {
            'pool': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'name': 'pool1name',
                'description': 'pool1description',
                'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                'protocol': 'HTTP',
                'lb_method': 'ROUND_ROBIN',
                'admin_state_up': True
            }
        }
        quantumclient.create_pool({'pool': form_data}).AndReturn(pool)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Pool)
Пример #2
0
    def test_member_update(self):
        form_data = {
            'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
            'address': '10.0.1.4',
            'protocol_port': '80',
            'weight': '10',
            'admin_state_up': True
        }

        member = {
            'member': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'address': '10.0.1.2',
                'protocol_port': '80',
                'weight': '10',
                'admin_state_up': True
            }
        }

        quantumclient.update_member(member['member']['id'],
                                    form_data).AndReturn(member)
        self.mox.ReplayAll()

        ret_val = api.lbaas.member_update(self.request, member['member']['id'],
                                          **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Member)
Пример #3
0
    def test_pool_update(self):
        form_data = {
            'name': 'pool1name',
            'description': 'pool1description',
            'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
            'protocol': 'HTTPS',
            'lb_method': 'LEAST_CONNECTION',
            'admin_state_up': True
        }

        pool = {
            'pool': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'name': 'pool1name',
                'description': 'pool1description',
                'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                'protocol': 'HTTPS',
                'lb_method': 'LEAST_CONNECTION',
                'admin_state_up': True
            }
        }
        quantumclient.update_pool(pool['pool']['id'],
                                  form_data).AndReturn(pool)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_update(self.request, pool['pool']['id'],
                                        **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Pool)
Пример #4
0
    def test_vip_update(self):
        form_data = {
            'address': '10.0.0.100',
            'name': 'vip1name',
            'description': 'vip1description',
            'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
            'protocol_port': '80',
            'protocol': 'HTTP',
            'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
            'connection_limit': '10',
            'admin_state_up': True
        }

        vip = {
            'vip': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'address': '10.0.0.100',
                'name': 'vip1name',
                'description': 'vip1description',
                'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                'protocol_port': '80',
                'protocol': 'HTTP',
                'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
                'connection_limit': '10',
                'admin_state_up': True
            }
        }
        quantumclient.update_vip(vip['vip']['id'], form_data).AndReturn(vip)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vip_update(self.request, vip['vip']['id'],
                                       **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Vip)
Пример #5
0
    def test_vip_update(self):
        form_data = {
            "address": "10.0.0.100",
            "name": "vip1name",
            "description": "vip1description",
            "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
            "protocol_port": "80",
            "protocol": "HTTP",
            "pool_id": "8913dde8-4915-4b90-8d3e-b95eeedb0d49",
            "connection_limit": "10",
            "admin_state_up": True,
        }

        vip = {
            "vip": {
                "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                "address": "10.0.0.100",
                "name": "vip1name",
                "description": "vip1description",
                "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
                "protocol_port": "80",
                "protocol": "HTTP",
                "pool_id": "8913dde8-4915-4b90-8d3e-b95eeedb0d49",
                "connection_limit": "10",
                "admin_state_up": True,
            }
        }
        quantumclient.update_vip(vip["vip"]["id"], form_data).AndReturn(vip)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vip_update(self.request, vip["vip"]["id"], **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Vip)
Пример #6
0
    def test_pool_create(self):
        form_data = {
            "name": "pool1name",
            "description": "pool1description",
            "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
            "protocol": "HTTP",
            "lb_method": "ROUND_ROBIN",
            "admin_state_up": True,
        }

        pool = {
            "pool": {
                "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                "name": "pool1name",
                "description": "pool1description",
                "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
                "protocol": "HTTP",
                "lb_method": "ROUND_ROBIN",
                "admin_state_up": True,
            }
        }
        quantumclient.create_pool({"pool": form_data}).AndReturn(pool)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Pool)
Пример #7
0
    def test_pool_update(self):
        form_data = {
            "name": "pool1name",
            "description": "pool1description",
            "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
            "protocol": "HTTPS",
            "lb_method": "LEAST_CONNECTION",
            "admin_state_up": True,
        }

        pool = {
            "pool": {
                "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                "name": "pool1name",
                "description": "pool1description",
                "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
                "protocol": "HTTPS",
                "lb_method": "LEAST_CONNECTION",
                "admin_state_up": True,
            }
        }
        quantumclient.update_pool(pool["pool"]["id"], form_data).AndReturn(pool)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_update(self.request, pool["pool"]["id"], **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Pool)
Пример #8
0
    def test_pool_health_monitor_create(self):
        form_data = {'type': 'PING',
                     'delay': '10',
                     'timeout': '10',
                     'max_retries': '10',
                     'admin_state_up': True
                     }
        form_data_with_pool_id = {
            'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
            'type': 'PING',
            'delay': '10',
            'timeout': '10',
            'max_retries': '10',
            'admin_state_up': True}
        monitor = {'health_monitor': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'type': 'PING',
                'delay': '10',
                'timeout': '10',
                'max_retries': '10',
                'admin_state_up': True}}
        monitor_id = {'health_monitor': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e'}}
        quantumclient.create_health_monitor({
                'health_monitor': form_data}).AndReturn(monitor)
        quantumclient.associate_health_monitor(
            form_data_with_pool_id['pool_id'], monitor_id)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitor_create(
            self.request, **form_data_with_pool_id)
        self.assertIsInstance(ret_val, api.lbaas.PoolMonitor)
Пример #9
0
    def test_vip_update(self):
        form_data = {'address': '10.0.0.100',
                     'name': 'vip1name',
                     'description': 'vip1description',
                     'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                     'protocol_port': '80',
                     'protocol': 'HTTP',
                     'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
                     'connection_limit': '10',
                     'admin_state_up': True
                     }

        vip = {'vip': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                       'address': '10.0.0.100',
                       'name': 'vip1name',
                       'description': 'vip1description',
                       'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                       'protocol_port': '80',
                       'protocol': 'HTTP',
                       'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
                       'connection_limit': '10',
                       'admin_state_up': True
                       }}
        quantumclient.update_vip(vip['vip']['id'], form_data).AndReturn(vip)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vip_update(self.request,
                                       vip['vip']['id'], **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Vip)
Пример #10
0
    def test_member_update(self):
        form_data = {
            "pool_id": "abcdef-c3eb-4fee-9763-12de3338041e",
            "address": "10.0.1.4",
            "protocol_port": "80",
            "weight": "10",
            "admin_state_up": True,
        }

        member = {
            "member": {
                "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                "pool_id": "abcdef-c3eb-4fee-9763-12de3338041e",
                "address": "10.0.1.2",
                "protocol_port": "80",
                "weight": "10",
                "admin_state_up": True,
            }
        }

        quantumclient.update_member(member["member"]["id"], form_data).AndReturn(member)
        self.mox.ReplayAll()

        ret_val = api.lbaas.member_update(self.request, member["member"]["id"], **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Member)
 def setUp(self):
     """Prepare the test environment"""
     self.mox = mox.Mox()
     self.endurl = ENDURL
     self.client = Client(token=TOKEN, endpoint_url=self.endurl)
     self.fake_stdout = FakeStdout()
     sys.stdout = self.fake_stdout
     self.old_find_resourceid = quantumv20.find_resourceid_by_name_or_id
     quantumv20.find_resourceid_by_name_or_id = self._find_resourceid
Пример #12
0
    def test_member_get(self):
        member = {'member': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                              'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                              'address': '10.0.1.2',
                              'protocol_port': '80',
                              'weight': '10',
                              'admin_state_up': True}}
        quantumclient.show_member(member['member']['id']).AndReturn(member)
        self.mox.ReplayAll()

        ret_val = api.lbaas.member_get(self.request, member['member']['id'])
        self.assertIsInstance(ret_val, api.lbaas.Member)
Пример #13
0
    def test_pool_health_monitor_create(self):
        form_data = {
            'type': 'PING',
            'delay': '10',
            'timeout': '10',
            'max_retries': '10',
            'http_method': 'GET',
            'url_path': '/monitor',
            'expected_codes': '200',
            'admin_state_up': True
        }
        form_data_with_pool_id = {
            'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
            'type': 'PING',
            'delay': '10',
            'timeout': '10',
            'max_retries': '10',
            'http_method': 'GET',
            'url_path': '/monitor',
            'expected_codes': '200',
            'admin_state_up': True
        }
        monitor = {
            'health_monitor': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'type': 'PING',
                'delay': '10',
                'timeout': '10',
                'max_retries': '10',
                'http_method': 'GET',
                'url_path': '/monitor',
                'expected_codes': '200',
                'admin_state_up': True
            }
        }
        monitor_id = {
            'health_monitor': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e'
            }
        }
        quantumclient.create_health_monitor({
            'health_monitor': form_data
        }).AndReturn(monitor)
        quantumclient.associate_health_monitor(
            form_data_with_pool_id['pool_id'], monitor_id)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitor_create(
            self.request, **form_data_with_pool_id)
        self.assertIsInstance(ret_val, api.lbaas.PoolMonitor)
Пример #14
0
    def test_pool_get(self):
        pool = {'pool': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                         'name': 'pool1name',
                         'description': 'pool1description',
                         'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                         'protocol': 'HTTP',
                         'lb_method': 'ROUND_ROBIN',
                         'admin_state_up': True
                         }}
        quantumclient.show_pool(pool['pool']['id']).AndReturn(pool)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_get(self.request, pool['pool']['id'])
        self.assertIsInstance(ret_val, api.lbaas.Pool)
Пример #15
0
    def test_members_get(self):
        members = {'members': [
                {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                 'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                 'address': '10.0.1.2',
                 'protocol_port': '80',
                 'weight': '10',
                 'admin_state_up': True
                 }, ]}
        quantumclient.list_members().AndReturn(members)
        self.mox.ReplayAll()

        ret_val = api.lbaas.members_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Member)
Пример #16
0
    def test_pools_get(self):
        pools = {'pools': [{
                    'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'name': 'pool1name',
                    'description': 'pool1description',
                    'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                    'protocol': 'HTTP',
                    'lb_method': 'ROUND_ROBIN',
                    'admin_state_up': True}, ]}
        quantumclient.list_pools().AndReturn(pools)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pools_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Pool)
Пример #17
0
 def setUp(self):
     """Prepare the test environment"""
     self.mox = mox.Mox()
     self.endurl = ENDURL
     self.client = Client(token=TOKEN, endpoint_url=self.endurl)
     self.fake_stdout = FakeStdout()
     sys.stdout = self.fake_stdout
Пример #18
0
    def test_pool_health_monitor_create(self):
        form_data = {"type": "PING", "delay": "10", "timeout": "10", "max_retries": "10", "admin_state_up": True}
        monitor = {
            "health_monitor": {
                "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                "type": "PING",
                "delay": "10",
                "timeout": "10",
                "max_retries": "10",
                "admin_state_up": True,
            }
        }
        quantumclient.create_health_monitor({"health_monitor": form_data}).AndReturn(monitor)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitor_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api.lbaas.PoolMonitor)
Пример #19
0
 def setUp(self):
     """Prepare the test environment."""
     super(CLITestNameorID, self).setUp()
     self.mox = mox.Mox()
     self.endurl = test_cli20.ENDURL
     self.client = Client(token=test_cli20.TOKEN, endpoint_url=self.endurl)
     self.addCleanup(self.mox.VerifyAll)
     self.addCleanup(self.mox.UnsetStubs)
 def setUp(self):
     """Prepare the test environment"""
     self.mox = mox.Mox()
     self.endurl = ENDURL
     self.client = Client(token=TOKEN, endpoint_url=self.endurl)
     self.fake_stdout = FakeStdout()
     sys.stdout = self.fake_stdout
     self.old_find_resourceid = quantumv20.find_resourceid_by_name_or_id
     quantumv20.find_resourceid_by_name_or_id = self._find_resourceid
Пример #21
0
    def test_pool_health_monitor_get(self):
        monitor = {'health_monitor':
                   {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'type': 'PING',
                    'delay': '10',
                    'timeout': '10',
                    'max_retries': '10',
                    'http_method': 'GET',
                    'url_path': '/monitor',
                    'expected_codes': '200',
                    'admin_state_up': True}}
        quantumclient.show_health_monitor(
            monitor['health_monitor']['id']).AndReturn(monitor)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitor_get(
            self.request, monitor['health_monitor']['id'])
        self.assertIsInstance(ret_val, api.lbaas.PoolMonitor)
Пример #22
0
    def test_pool_health_monitors_get(self):
        monitors = {'health_monitors': [
                {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                 'type': 'PING',
                 'delay': '10',
                 'timeout': '10',
                 'max_retries': '10',
                 'http_method': 'GET',
                 'url_path': '/monitor',
                 'expected_codes': '200',
                 'admin_state_up': True}, ]}

        quantumclient.list_health_monitors().AndReturn(monitors)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitors_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.PoolMonitor)
Пример #23
0
    def test_vips_get(self):
        vips = {'vips': [{'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                          'address': '10.0.0.100',
                          'name': 'vip1name',
                          'description': 'vip1description',
                          'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                          'protocol_port': '80',
                          'protocol': 'HTTP',
                          'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
                          'connection_limit': '10',
                          'admin_state_up': True
                          }, ]}
        quantumclient.list_vips().AndReturn(vips)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vips_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Vip)
Пример #24
0
    def test_members_get(self):
        members = {
            'members': [
                {
                    'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'address': '10.0.1.2',
                    'protocol_port': '80',
                    'weight': '10',
                    'admin_state_up': True
                },
            ]
        }
        quantumclient.list_members().AndReturn(members)
        self.mox.ReplayAll()

        ret_val = api.lbaas.members_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Member)
Пример #25
0
    def test_pool_health_monitor_get(self):
        monitor = {
            "health_monitor": {
                "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                "type": "PING",
                "delay": "10",
                "timeout": "10",
                "max_retries": "10",
                "http_method": "GET",
                "url_path": "/monitor",
                "expected_codes": "200",
                "admin_state_up": True,
            }
        }
        quantumclient.show_health_monitor(monitor["health_monitor"]["id"]).AndReturn(monitor)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitor_get(self.request, monitor["health_monitor"]["id"])
        self.assertIsInstance(ret_val, api.lbaas.PoolMonitor)
Пример #26
0
    def test_vip_create(self):
        vip1 = self.api_vips.first()
        form_data = {'address': vip1['address'],
                     'name': vip1['name'],
                     'description': vip1['description'],
                     'subnet_id': vip1['subnet_id'],
                     'protocol_port': vip1['protocol_port'],
                     'protocol': vip1['protocol'],
                     'pool_id': vip1['pool_id'],
                     'session_persistence': vip1['session_persistence'],
                     'connection_limit': vip1['connection_limit'],
                     'admin_state_up': vip1['admin_state_up']
                     }
        vip = {'vip': self.api_vips.first()}
        quantumclient.create_vip({'vip': form_data}).AndReturn(vip)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vip_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Vip)
Пример #27
0
    def test_members_get(self):
        members = {
            "members": [
                {
                    "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                    "pool_id": "abcdef-c3eb-4fee-9763-12de3338041e",
                    "address": "10.0.1.2",
                    "protocol_port": "80",
                    "weight": "10",
                    "admin_state_up": True,
                }
            ]
        }
        quantumclient.list_members().AndReturn(members)
        self.mox.ReplayAll()

        ret_val = api.lbaas.members_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Member)
Пример #28
0
    def test_vip_create(self):
        vip1 = self.api_vips.first()
        form_data = {
            'address': vip1['address'],
            'name': vip1['name'],
            'description': vip1['description'],
            'subnet_id': vip1['subnet_id'],
            'protocol_port': vip1['protocol_port'],
            'protocol': vip1['protocol'],
            'pool_id': vip1['pool_id'],
            'session_persistence': vip1['session_persistence'],
            'connection_limit': vip1['connection_limit'],
            'admin_state_up': vip1['admin_state_up']
        }
        vip = {'vip': self.api_vips.first()}
        quantumclient.create_vip({'vip': form_data}).AndReturn(vip)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vip_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Vip)
Пример #29
0
    def test_pools_get(self):
        pools = {
            "pools": [
                {
                    "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                    "name": "pool1name",
                    "description": "pool1description",
                    "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
                    "protocol": "HTTP",
                    "lb_method": "ROUND_ROBIN",
                    "admin_state_up": True,
                }
            ]
        }
        quantumclient.list_pools().AndReturn(pools)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pools_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Pool)
Пример #30
0
    def test_pools_get(self):
        pools = {
            'pools': [
                {
                    'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'name': 'pool1name',
                    'description': 'pool1description',
                    'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                    'protocol': 'HTTP',
                    'lb_method': 'ROUND_ROBIN',
                    'admin_state_up': True
                },
            ]
        }
        quantumclient.list_pools().AndReturn(pools)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pools_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Pool)
Пример #31
0
    def test_vip_create(self):
        vip1 = self.api_vips.first()
        form_data = {
            "address": vip1["address"],
            "name": vip1["name"],
            "description": vip1["description"],
            "subnet_id": vip1["subnet_id"],
            "protocol_port": vip1["protocol_port"],
            "protocol": vip1["protocol"],
            "pool_id": vip1["pool_id"],
            "session_persistence": vip1["session_persistence"],
            "connection_limit": vip1["connection_limit"],
            "admin_state_up": vip1["admin_state_up"],
        }
        vip = {"vip": self.api_vips.first()}
        quantumclient.create_vip({"vip": form_data}).AndReturn(vip)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vip_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Vip)
Пример #32
0
 def setUp(self):
     """Prepare the test environment"""
     super(CLITestV20Base, self).setUp()
     self.mox = mox.Mox()
     self.endurl = ENDURL
     self.client = Client(token=TOKEN, endpoint_url=self.endurl)
     self.fake_stdout = FakeStdout()
     self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.fake_stdout))
     self.useFixture(fixtures.MonkeyPatch(
         'quantumclient.quantum.v2_0.find_resourceid_by_name_or_id',
         self._find_resourceid))
Пример #33
0
    def test_member_create(self):
        form_data = {'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                     'address': '10.0.1.2',
                     'protocol_port': '80',
                     'weight': '10',
                     'admin_state_up': True
                     }

        member = {'member':
                  {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                   'pool_id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                   'address': '10.0.1.2',
                   'protocol_port': '80',
                   'weight': '10',
                   'admin_state_up': True}}

        quantumclient.create_member({'member': form_data}).AndReturn(member)
        self.mox.ReplayAll()

        ret_val = api.lbaas.member_create(self.request, **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Member)
Пример #34
0
    def test_pool_health_monitor_get(self):
        monitor = {
            'health_monitor': {
                'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                'type': 'PING',
                'delay': '10',
                'timeout': '10',
                'max_retries': '10',
                'http_method': 'GET',
                'url_path': '/monitor',
                'expected_codes': '200',
                'admin_state_up': True
            }
        }
        quantumclient.show_health_monitor(
            monitor['health_monitor']['id']).AndReturn(monitor)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitor_get(
            self.request, monitor['health_monitor']['id'])
        self.assertIsInstance(ret_val, api.lbaas.PoolMonitor)
Пример #35
0
    def test_pool_health_monitors_get(self):
        monitors = {
            "health_monitors": [
                {
                    "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                    "type": "PING",
                    "delay": "10",
                    "timeout": "10",
                    "max_retries": "10",
                    "http_method": "GET",
                    "url_path": "/monitor",
                    "expected_codes": "200",
                    "admin_state_up": True,
                }
            ]
        }

        quantumclient.list_health_monitors().AndReturn(monitors)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitors_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.PoolMonitor)
Пример #36
0
    def test_vips_get(self):
        vips = {
            'vips': [
                {
                    'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'address': '10.0.0.100',
                    'name': 'vip1name',
                    'description': 'vip1description',
                    'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                    'protocol_port': '80',
                    'protocol': 'HTTP',
                    'pool_id': '8913dde8-4915-4b90-8d3e-b95eeedb0d49',
                    'connection_limit': '10',
                    'admin_state_up': True
                },
            ]
        }
        quantumclient.list_vips().AndReturn(vips)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vips_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Vip)
Пример #37
0
    def test_vips_get(self):
        vips = {
            "vips": [
                {
                    "id": "abcdef-c3eb-4fee-9763-12de3338041e",
                    "address": "10.0.0.100",
                    "name": "vip1name",
                    "description": "vip1description",
                    "subnet_id": "12381d38-c3eb-4fee-9763-12de3338041e",
                    "protocol_port": "80",
                    "protocol": "HTTP",
                    "pool_id": "8913dde8-4915-4b90-8d3e-b95eeedb0d49",
                    "connection_limit": "10",
                    "admin_state_up": True,
                }
            ]
        }
        quantumclient.list_vips().AndReturn(vips)
        self.mox.ReplayAll()

        ret_val = api.lbaas.vips_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.Vip)
Пример #38
0
    def test_pool_health_monitors_get(self):
        monitors = {
            'health_monitors': [
                {
                    'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                    'type': 'PING',
                    'delay': '10',
                    'timeout': '10',
                    'max_retries': '10',
                    'http_method': 'GET',
                    'url_path': '/monitor',
                    'expected_codes': '200',
                    'admin_state_up': True
                },
            ]
        }

        quantumclient.list_health_monitors().AndReturn(monitors)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_health_monitors_get(self.request)
        for v in ret_val:
            self.assertIsInstance(v, api.lbaas.PoolMonitor)
Пример #39
0
    def test_pool_update(self):
        form_data = {'name': 'pool1name',
                     'description': 'pool1description',
                     'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                     'protocol': 'HTTPS',
                     'lb_method': 'LEAST_CONNECTION',
                     'admin_state_up': True
                     }

        pool = {'pool': {'id': 'abcdef-c3eb-4fee-9763-12de3338041e',
                         'name': 'pool1name',
                         'description': 'pool1description',
                         'subnet_id': '12381d38-c3eb-4fee-9763-12de3338041e',
                         'protocol': 'HTTPS',
                         'lb_method': 'LEAST_CONNECTION',
                         'admin_state_up': True
                         }}
        quantumclient.update_pool(pool['pool']['id'],
                                  form_data).AndReturn(pool)
        self.mox.ReplayAll()

        ret_val = api.lbaas.pool_update(self.request,
                                        pool['pool']['id'], **form_data)
        self.assertIsInstance(ret_val, api.lbaas.Pool)
class CLITestV20Base(unittest.TestCase):

    test_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'

    def _find_resourceid(self, client, resource, name_or_id):
        return name_or_id

    def setUp(self):
        """Prepare the test environment"""
        self.mox = mox.Mox()
        self.endurl = ENDURL
        self.client = Client(token=TOKEN, endpoint_url=self.endurl)
        self.fake_stdout = FakeStdout()
        sys.stdout = self.fake_stdout
        self.old_find_resourceid = quantumv20.find_resourceid_by_name_or_id
        quantumv20.find_resourceid_by_name_or_id = self._find_resourceid

    def tearDown(self):
        """Clear the test environment"""
        sys.stdout = sys.__stdout__
        quantumv20.find_resourceid_by_name_or_id = self.old_find_resourceid

    def _test_create_resource(self,
                              resource,
                              cmd,
                              name,
                              myid,
                              args,
                              position_names,
                              position_values,
                              tenant_id=None,
                              tags=None,
                              admin_state_up=True,
                              shared=False):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        if (resource == 'subnet' or resource == 'floatingip'):
            body = {
                resource: {},
            }
        else:
            body = {
                resource: {
                    'admin_state_up': admin_state_up,
                },
            }
        if tenant_id:
            body[resource].update({'tenant_id': tenant_id})
        if tags:
            body[resource].update({'tags': tags})
        if shared:
            body[resource].update({'shared': shared})

        for i in xrange(len(position_names)):
            body[resource].update({position_names[i]: position_values[i]})
        ress = {
            resource: {
                'id': myid,
                'name': name,
            },
        }
        resstr = self.client.serialize(ress)
        # url method body
        path = getattr(self.client, resource + "s_path")
        self.client.httpclient.request(end_url(path),
                                       'POST',
                                       body=MyComparator(body, self.client),
                                       headers=ContainsKeyValue(
                                           'X-Auth-Token', TOKEN)).AndReturn(
                                               (MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser('create_' + resource)
        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        self.assertTrue(name in _str)

    def _test_list_columns(self,
                           cmd,
                           resources_collection,
                           resources_out,
                           args=['-f', 'json']):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        resstr = self.client.serialize(resources_out)

        path = getattr(self.client, resources_collection + "_path")
        self.client.httpclient.request(end_url(path),
                                       'GET',
                                       body=None,
                                       headers=ContainsKeyValue(
                                           'X-Auth-Token', TOKEN)).AndReturn(
                                               (MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources_collection)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()

    def _test_list_resources(self,
                             resources,
                             cmd,
                             detail=False,
                             tags=[],
                             fields_1=[],
                             fields_2=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        reses = {
            resources: [
                {
                    'id': 'myid1',
                },
                {
                    'id': 'myid2',
                },
            ],
        }
        resstr = self.client.serialize(reses)
        # url method body
        query = ""
        args = detail and [
            '-D',
        ] or []
        if fields_1:
            for field in fields_1:
                args.append('--fields')
                args.append(field)

        if tags:
            args.append('--')
            args.append("--tag")
        for tag in tags:
            if query:
                query += "&tag=" + tag
            else:
                query = "tag=" + tag
            args.append(tag)
        if (not tags) and fields_2:
            args.append('--')
        if fields_2:
            args.append("--fields")
            for field in fields_2:
                args.append(field)
        if detail:
            query = query and query + '&verbose=True' or 'verbose=True'
        fields_1.extend(fields_2)
        for field in fields_1:
            if query:
                query += "&fields=" + field
            else:
                query = "fields=" + field
        path = getattr(self.client, resources + "_path")
        self.client.httpclient.request(end_url(path, query),
                                       'GET',
                                       body=None,
                                       headers=ContainsKeyValue(
                                           'X-Auth-Token', TOKEN)).AndReturn(
                                               (MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue('myid1' in _str)

    def _test_update_resource(self, resource, cmd, myid, args, extrafields):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        body = {resource: extrafields}
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(end_url(path % myid),
                                       'PUT',
                                       body=MyComparator(body, self.client),
                                       headers=ContainsKeyValue(
                                           'X-Auth-Token', TOKEN)).AndReturn(
                                               (MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("update_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)

    def _test_show_resource(self, resource, cmd, myid, args, fields=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        query = "&".join(["fields=%s" % field for field in fields])
        expected_res = {
            resource: {
                'id': myid,
                'name': 'myname',
            },
        }
        resstr = self.client.serialize(expected_res)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(end_url(path % myid, query),
                                       'GET',
                                       body=None,
                                       headers=ContainsKeyValue(
                                           'X-Auth-Token', TOKEN)).AndReturn(
                                               (MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("show_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        self.assertTrue('myname' in _str)

    def _test_delete_resource(self, resource, cmd, myid, args):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(end_url(path % myid),
                                       'DELETE',
                                       body=None,
                                       headers=ContainsKeyValue(
                                           'X-Auth-Token', TOKEN)).AndReturn(
                                               (MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("delete_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)

    def _test_update_resource_action(self, resource, cmd, myid, action, args,
                                     body):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        path = getattr(self.client, resource + "_path")
        path_action = '%s/%s' % (myid, action)
        self.client.httpclient.request(end_url(path % path_action),
                                       'PUT',
                                       body=MyComparator(body, self.client),
                                       headers=ContainsKeyValue(
                                           'X-Auth-Token', TOKEN)).AndReturn(
                                               (MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("update_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
Пример #41
0
class CLITestV20Base(unittest.TestCase):

    test_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'

    def _url(self, path, query=None):
        _url_str = self.endurl + "/v" + API_VERSION + path + "." + FORMAT
        return query and _url_str + "?" + query or _url_str

    def setUp(self):
        """Prepare the test environment"""
        self.mox = mox.Mox()
        self.endurl = ENDURL
        self.client = Client(token=TOKEN, endpoint_url=self.endurl)
        self.fake_stdout = FakeStdout()
        sys.stdout = self.fake_stdout

    def tearDown(self):
        """Clear the test environment"""
        sys.stdout = sys.__stdout__

    def _test_create_resource(self, resource, cmd,
                              name, myid, args,
                              position_names, position_values, tenant_id=None,
                              tags=None, admin_state_up=True):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        if resource == 'subnet':
            body = {resource: {}, }
        else:
            body = {resource: {'admin_state_up': admin_state_up, }, }
        if tenant_id:
            body[resource].update({'tenant_id': tenant_id})
        if tags:
            body[resource].update({'tags': tags})
        for i in xrange(len(position_names)):
            body[resource].update({position_names[i]: position_values[i]})
        ress = {resource:
                {'id': myid,
                 'name': name, }, }
        resstr = self.client.serialize(ress)
        # url method body
        path = getattr(self.client, resource + "s_path")
        self.client.httpclient.request(
            self._url(path), 'POST',
            body=MyComparator(body, self.client),
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200),
                                                        resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser('create_' + resource)
        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        self.assertTrue(name in _str)

    def _test_list_resources(self, resources, cmd, detail=False, tags=[],
                             fields_1=[], fields_2=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        reses = {resources: [{'id': 'myid1', },
                             {'id': 'myid2', }, ], }
        resstr = self.client.serialize(reses)
        # url method body
        query = ""
        args = detail and ['-D', ] or []
        if fields_1:
            for field in fields_1:
                args.append('--fields')
                args.append(field)

        if tags:
            args.append('--')
            args.append("--tag")
        for tag in tags:
            if query:
                query += "&tag=" + tag
            else:
                query = "tag=" + tag
            args.append(tag)
        if (not tags) and fields_2:
            args.append('--')
        if fields_2:
            args.append("--fields")
            for field in fields_2:
                args.append(field)
        if detail:
            query = query and query + '&verbose=True' or 'verbose=True'
        fields_1.extend(fields_2)
        for field in fields_1:
            if query:
                query += "&fields=" + field
            else:
                query = "fields=" + field
        path = getattr(self.client, resources + "_path")
        self.client.httpclient.request(
            self._url(path, query), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue('myid1' in _str)

    def _test_update_resource(self, resource, cmd, myid, args, extrafields):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        body = {resource: extrafields}
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            self._url(path % myid), 'PUT',
            body=MyComparator(body, self.client),
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("update_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)

    def _test_show_resource(self, resource, cmd, myid, args, fields=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        query = "&".join(["fields=%s" % field for field in fields])
        expected_res = {resource:
                        {'id': myid,
                        'name': 'myname', }, }
        resstr = self.client.serialize(expected_res)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            self._url(path % myid, query), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("show_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        self.assertTrue('myname' in _str)

    def _test_show_resource_by_name(self, resource, cmd, name,
                                    args, fields=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        query = "&".join(["fields=%s" % field for field in fields])
        expected_res = {"%ss" % resource:
                        [{'id': 'some_id',
                          'name': name, }], }
        resstr = self.client.serialize(expected_res)
        list_path = getattr(self.client, resource + "s_path")
        self.client.httpclient.request(
            self._url(list_path, "%s&name=%s" % (query, name)), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("show_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(name in _str)
        self.assertTrue('some_id' in _str)

    def _test_delete_resource(self, resource, cmd, myid, args):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            self._url(path % myid), 'DELETE',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("delete_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
Пример #42
0
class CLITestNameorID(unittest.TestCase):
    def setUp(self):
        """Prepare the test environment"""
        self.mox = mox.Mox()
        self.endurl = test_cli20.ENDURL
        self.client = Client(token=test_cli20.TOKEN, endpoint_url=self.endurl)

    def tearDown(self):
        """Clear the test environment"""
        self.mox.VerifyAll()
        self.mox.UnsetStubs()

    def test_get_id_from_id(self):
        _id = str(uuid.uuid4())
        reses = {
            'networks': [
                {
                    'id': _id,
                },
            ],
        }
        resstr = self.client.serialize(reses)
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        path = getattr(self.client, "networks_path")
        self.client.httpclient.request(
            test_cli20.end_url(path, "fields=id&id=" + _id),
            'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(
                                         (test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        returned_id = quantumv20.find_resourceid_by_name_or_id(
            self.client, 'network', _id)
        self.assertEqual(_id, returned_id)

    def test_get_id_from_id_then_name_empty(self):
        _id = str(uuid.uuid4())
        reses = {
            'networks': [
                {
                    'id': _id,
                },
            ],
        }
        resstr = self.client.serialize(reses)
        resstr1 = self.client.serialize({'networks': []})
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        path = getattr(self.client, "networks_path")
        self.client.httpclient.request(
            test_cli20.end_url(path, "fields=id&id=" + _id),
            'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(
                                         (test_cli20.MyResp(200), resstr1))
        self.client.httpclient.request(
            test_cli20.end_url(path, "fields=id&name=" + _id),
            'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(
                                         (test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        returned_id = quantumv20.find_resourceid_by_name_or_id(
            self.client, 'network', _id)
        self.assertEqual(_id, returned_id)

    def test_get_id_from_name(self):
        name = 'myname'
        _id = str(uuid.uuid4())
        reses = {
            'networks': [
                {
                    'id': _id,
                },
            ],
        }
        resstr = self.client.serialize(reses)
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        path = getattr(self.client, "networks_path")
        self.client.httpclient.request(
            test_cli20.end_url(path, "fields=id&name=" + name),
            'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(
                                         (test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        returned_id = quantumv20.find_resourceid_by_name_or_id(
            self.client, 'network', name)
        self.assertEqual(_id, returned_id)

    def test_get_id_from_name_multiple(self):
        name = 'myname'
        reses = {
            'networks': [{
                'id': str(uuid.uuid4())
            }, {
                'id': str(uuid.uuid4())
            }]
        }
        resstr = self.client.serialize(reses)
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        path = getattr(self.client, "networks_path")
        self.client.httpclient.request(
            test_cli20.end_url(path, "fields=id&name=" + name),
            'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(
                                         (test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        try:
            quantumv20.find_resourceid_by_name_or_id(self.client, 'network',
                                                     name)
        except exceptions.QuantumClientException as ex:
            self.assertTrue('Multiple' in ex.message)

    def test_get_id_from_name_notfound(self):
        name = 'myname'
        reses = {'networks': []}
        resstr = self.client.serialize(reses)
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        path = getattr(self.client, "networks_path")
        self.client.httpclient.request(
            test_cli20.end_url(path, "fields=id&name=" + name),
            'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     test_cli20.TOKEN)).AndReturn(
                                         (test_cli20.MyResp(200), resstr))
        self.mox.ReplayAll()
        try:
            quantumv20.find_resourceid_by_name_or_id(self.client, 'network',
                                                     name)
        except exceptions.QuantumClientException as ex:
            self.assertTrue('Unable to find' in ex.message)
            self.assertEqual(404, ex.status_code)
Пример #43
0
 def setUp(self):
     """Prepare the test environment"""
     self.mox = mox.Mox()
     self.endurl = test_cli20.ENDURL
     self.client = Client(token=test_cli20.TOKEN, endpoint_url=self.endurl)
Пример #44
0
class CLITestV20Base(testtools.TestCase):

    test_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'

    def _find_resourceid(self, client, resource, name_or_id):
        return name_or_id

    def setUp(self):
        """Prepare the test environment"""
        super(CLITestV20Base, self).setUp()
        self.mox = mox.Mox()
        self.endurl = ENDURL
        self.client = Client(token=TOKEN, endpoint_url=self.endurl)
        self.fake_stdout = FakeStdout()
        self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.fake_stdout))
        self.useFixture(fixtures.MonkeyPatch(
            'quantumclient.quantum.v2_0.find_resourceid_by_name_or_id',
            self._find_resourceid))

    def _test_create_resource(self, resource, cmd,
                              name, myid, args,
                              position_names, position_values, tenant_id=None,
                              tags=None, admin_state_up=True, shared=False,
                              extra_body=None, **kwargs):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        non_admin_status_resources = ['subnet', 'floatingip', 'security_group',
                                      'security_group_rule', 'qos_queue',
                                      'network_gateway']
        if (resource in non_admin_status_resources):
            body = {resource: {}, }
        else:
            body = {resource: {'admin_state_up': admin_state_up, }, }
        if tenant_id:
            body[resource].update({'tenant_id': tenant_id})
        if tags:
            body[resource].update({'tags': tags})
        if shared:
            body[resource].update({'shared': shared})
        if extra_body:
            body[resource].update(extra_body)
        body[resource].update(kwargs)

        for i in xrange(len(position_names)):
            body[resource].update({position_names[i]: position_values[i]})
        ress = {resource:
                {'id': myid}, }
        if name:
            ress[resource].update({'name': name})
        resstr = self.client.serialize(ress)
        # url method body
        path = getattr(self.client, resource + "s_path")
        self.client.httpclient.request(
            end_url(path), 'POST',
            body=MyComparator(body, self.client),
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200),
                                                        resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser('create_' + resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        if name:
            self.assertTrue(name in _str)

    def _test_list_columns(self, cmd, resources_collection,
                           resources_out, args=['-f', 'json']):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        resstr = self.client.serialize(resources_out)

        path = getattr(self.client, resources_collection + "_path")
        self.client.httpclient.request(
            end_url(path), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources_collection)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()

    def _test_list_resources(self, resources, cmd, detail=False, tags=[],
                             fields_1=[], fields_2=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        reses = {resources: [{'id': 'myid1', },
                             {'id': 'myid2', }, ], }
        resstr = self.client.serialize(reses)
        # url method body
        query = ""
        args = detail and ['-D', ] or []
        if fields_1:
            for field in fields_1:
                args.append('--fields')
                args.append(field)

        if tags:
            args.append('--')
            args.append("--tag")
        for tag in tags:
            if query:
                query += "&tag=" + tag
            else:
                query = "tag=" + tag
            args.append(tag)
        if (not tags) and fields_2:
            args.append('--')
        if fields_2:
            args.append("--fields")
            for field in fields_2:
                args.append(field)
        if detail:
            query = query and query + '&verbose=True' or 'verbose=True'
        fields_1.extend(fields_2)
        for field in fields_1:
            if query:
                query += "&fields=" + field
            else:
                query = "fields=" + field
        path = getattr(self.client, resources + "_path")
        self.client.httpclient.request(
            MyUrlComparator(end_url(path, query), self.client), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue('myid1' in _str)

    def _test_update_resource(self, resource, cmd, myid, args, extrafields):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        body = {resource: extrafields}
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            MyUrlComparator(end_url(path % myid), self.client), 'PUT',
            body=MyComparator(body, self.client),
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("update_" + resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)

    def _test_show_resource(self, resource, cmd, myid, args, fields=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        query = "&".join(["fields=%s" % field for field in fields])
        expected_res = {resource:
                        {'id': myid,
                        'name': 'myname', }, }
        resstr = self.client.serialize(expected_res)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            end_url(path % myid, query), 'GET',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("show_" + resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        self.assertTrue('myname' in _str)

    def _test_delete_resource(self, resource, cmd, myid, args):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            end_url(path % myid), 'DELETE',
            body=None,
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("delete_" + resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)

    def _test_update_resource_action(self, resource, cmd, myid, action, args,
                                     body):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        path = getattr(self.client, resource + "_path")
        path_action = '%s/%s' % (myid, action)
        self.client.httpclient.request(
            end_url(path % path_action), 'PUT',
            body=MyComparator(body, self.client),
            headers=ContainsKeyValue('X-Auth-Token',
                                     TOKEN)).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("delete_" + resource)
        shell.run_command(cmd, cmd_parser, args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
Пример #45
0
class CLITestV20Base(unittest.TestCase):
    def _url(self, path, query=None):
        _url_str = self.endurl + "/v" + API_VERSION + path + "." + FORMAT
        return query and _url_str + "?" + query or _url_str

    def setUp(self):
        """Prepare the test environment"""
        self.mox = mox.Mox()
        self.endurl = ENDURL
        self.client = Client(token=TOKEN, endpoint_url=self.endurl)
        self.fake_stdout = FakeStdout()
        sys.stdout = self.fake_stdout

    def tearDown(self):
        """Clear the test environment"""
        sys.stdout = sys.__stdout__

    def _test_create_resource(
        self,
        resource,
        cmd,
        name,
        myid,
        args,
        position_names,
        position_values,
        tenant_id=None,
        tags=None,
        admin_state_up=True,
    ):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        if resource == "subnet":
            body = {resource: {}}
        else:
            body = {resource: {"admin_state_up": admin_state_up}}
        if tenant_id:
            body[resource].update({"tenant_id": tenant_id})
        if tags:
            body[resource].update({"tags": tags})
        for i in xrange(len(position_names)):
            body[resource].update({position_names[i]: position_values[i]})
        ress = {resource: {"id": myid, "name": name}}
        resstr = self.client.serialize(ress)
        # url method body
        path = getattr(self.client, resource + "s_path")
        self.client.httpclient.request(
            self._url(path),
            "POST",
            body=MyComparator(body, self.client),
            headers=ContainsKeyValue("X-Auth-Token", TOKEN),
        ).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("create_" + resource)
        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        self.assertTrue(name in _str)

    def _test_list_resources(self, resources, cmd, detail=False, tags=[], fields_1=[], fields_2=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        reses = {resources: [{"id": "myid1"}, {"id": "myid2"}]}
        resstr = self.client.serialize(reses)
        # url method body
        query = ""
        args = detail and ["-D"] or []
        if fields_1:
            for field in fields_1:
                args.append("--fields")
                args.append(field)

        if tags:
            args.append("--")
            args.append("--tag")
        for tag in tags:
            if query:
                query += "&tag=" + tag
            else:
                query = "tag=" + tag
            args.append(tag)
        if (not tags) and fields_2:
            args.append("--")
        if fields_2:
            args.append("--fields")
            for field in fields_2:
                args.append(field)
        if detail:
            query = query and query + "&verbose=True" or "verbose=True"
        fields_1.extend(fields_2)
        for field in fields_1:
            if query:
                query += "&fields=" + field
            else:
                query = "fields=" + field
        path = getattr(self.client, resources + "_path")
        self.client.httpclient.request(
            self._url(path, query), "GET", body=None, headers=ContainsKeyValue("X-Auth-Token", TOKEN)
        ).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("list_" + resources)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue("myid1" in _str)

    def _test_update_resource(self, resource, cmd, myid, args, extrafields):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        body = {resource: extrafields}
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            self._url(path % myid),
            "PUT",
            body=MyComparator(body, self.client),
            headers=ContainsKeyValue("X-Auth-Token", TOKEN),
        ).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("update_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)

    def _test_show_resource(self, resource, cmd, myid, args, fields=[]):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        query = None
        for field in fields:
            if query:
                query += "&fields=" + field
            else:
                query = "fields=" + field
        resnetworks = {resource: {"id": myid, "name": "myname"}}
        resstr = self.client.serialize(resnetworks)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            self._url(path % myid, query), "GET", body=None, headers=ContainsKeyValue("X-Auth-Token", TOKEN)
        ).AndReturn((MyResp(200), resstr))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("show_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)
        self.assertTrue("myname" in _str)

    def _test_delete_resource(self, resource, cmd, myid, args):
        self.mox.StubOutWithMock(cmd, "get_client")
        self.mox.StubOutWithMock(self.client.httpclient, "request")
        cmd.get_client().MultipleTimes().AndReturn(self.client)
        path = getattr(self.client, resource + "_path")
        self.client.httpclient.request(
            self._url(path % myid), "DELETE", body=None, headers=ContainsKeyValue("X-Auth-Token", TOKEN)
        ).AndReturn((MyResp(204), None))
        self.mox.ReplayAll()
        cmd_parser = cmd.get_parser("delete_" + resource)

        parsed_args = cmd_parser.parse_args(args)
        cmd.run(parsed_args)
        self.mox.VerifyAll()
        self.mox.UnsetStubs()
        _str = self.fake_stdout.make_string()
        self.assertTrue(myid in _str)