Esempio n. 1
0
 def test_get_bottom_mappings_by_top_id(self):
     for i in xrange(3):
         pod = {
             'pod_id': 'test_pod_uuid_%d' % i,
             'pod_name': 'test_pod_%d' % i,
             'az_name': 'test_az_uuid_%d' % i
         }
         api.create_pod(self.context, pod)
     route1 = {
         'top_id': 'top_uuid',
         'pod_id': 'test_pod_uuid_0',
         'resource_type': 'port'
     }
     route2 = {
         'top_id': 'top_uuid',
         'pod_id': 'test_pod_uuid_1',
         'bottom_id': 'bottom_uuid_1',
         'resource_type': 'port'
     }
     route3 = {
         'top_id': 'top_uuid',
         'pod_id': 'test_pod_uuid_2',
         'bottom_id': 'bottom_uuid_2',
         'resource_type': 'neutron'
     }
     routes = [route1, route2, route3]
     with self.context.session.begin():
         for route in routes:
             core.create_resource(self.context, models.ResourceRouting,
                                  route)
     mappings = api.get_bottom_mappings_by_top_id(self.context, 'top_uuid',
                                                  'port')
     self.assertEqual('test_pod_uuid_1', mappings[0][0]['pod_id'])
     self.assertEqual('bottom_uuid_1', mappings[0][1])
Esempio n. 2
0
    def setUp(self):
        core.initialize()
        core.ModelBase.metadata.create_all(core.get_engine())
        # enforce foreign key constraint for sqlite
        core.get_engine().execute('pragma foreign_keys=on')
        self.context = context.Context()

        pod_dict = {
            'pod_id': FAKE_SITE_ID,
            'pod_name': FAKE_SITE_NAME,
            'az_name': FAKE_AZ
        }
        config_dict = {
            'service_id': FAKE_SERVICE_ID,
            'pod_id': FAKE_SITE_ID,
            'service_type': FAKE_TYPE,
            'service_url': FAKE_URL
        }
        api.create_pod(self.context, pod_dict)
        api.create_pod_service_configuration(self.context, config_dict)

        global FAKE_RESOURCES
        FAKE_RESOURCES = [{'name': 'res1'}, {'name': 'res2'}]

        cfg.CONF.set_override(name='top_pod_name', override=FAKE_SITE_NAME,
                              group='client')
        self.client = client.Client()
        self.client.resource_service_map[FAKE_RESOURCE] = FAKE_TYPE
        self.client.operation_resources_map['list'].add(FAKE_RESOURCE)
        self.client.operation_resources_map['create'].add(FAKE_RESOURCE)
        self.client.operation_resources_map['delete'].add(FAKE_RESOURCE)
        self.client.operation_resources_map['action'].add(FAKE_RESOURCE)
        self.client.service_handle_map[FAKE_TYPE] = FakeResHandle(None)
Esempio n. 3
0
 def test_sort(self):
     pod1 = {
         'pod_id': 'test_pod1_uuid',
         'pod_name': 'test_pod1',
         'pod_az_name': 'test_pod_az_name1',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az1_uuid'
     }
     pod2 = {
         'pod_id': 'test_pod2_uuid',
         'pod_name': 'test_pod2',
         'pod_az_name': 'test_pod_az_name2',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az2_uuid'
     }
     pod3 = {
         'pod_id': 'test_pod3_uuid',
         'pod_name': 'test_pod3',
         'pod_az_name': 'test_pod_az_name3',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az3_uuid'
     }
     pods = [pod1, pod2, pod3]
     for pod in pods:
         api.create_pod(self.context, pod)
     pods = api.list_pods(self.context, sorts=[(models.Pod.pod_id, False)])
     self.assertEqual(pods, [pod3, pod2, pod1])
Esempio n. 4
0
    def test_update_binding(self):
        api.create_pod(self.context, self.b_pod_4)
        api.create_pod(self.context, self.b_pod_3)
        flag = self.pod_manager.create_binding(self.context,
                                               'new_project_pm_3',
                                               self.b_pod_3['pod_id'])
        self.assertEqual(flag, True)
        current_binding = core.query_resource(self.context, models.PodBinding,
                                              [{
                                                  'key': 'tenant_id',
                                                  'comparator': 'eq',
                                                  'value': 'new_project_pm_3'
                                              }], [])

        flag = self.pod_manager.update_binding(self.context,
                                               current_binding[0],
                                               self.b_pod_4['pod_id'])
        self.assertEqual(flag, True)
        binding_q = core.query_resource(self.context, models.PodBinding,
                                        [{
                                            'key': 'tenant_id',
                                            'comparator': 'eq',
                                            'value': 'new_project_pm_3'
                                        }], [])
        self.assertEqual(len(binding_q), 2)
        self.assertEqual(binding_q[0]['pod_id'], self.b_pod_3['pod_id'])
        self.assertEqual(binding_q[0]['tenant_id'], 'new_project_pm_3')
        self.assertEqual(binding_q[0]['is_binding'], False)
        self.assertEqual(binding_q[1]['pod_id'], self.b_pod_4['pod_id'])
        self.assertEqual(binding_q[1]['tenant_id'], 'new_project_pm_3')
        self.assertEqual(binding_q[1]['is_binding'], True)
Esempio n. 5
0
    def test_get_pod_and_endpoint_by_name(self):
        pod_dict = {
            'pod_id': 'fake_pod_id',
            'pod_name': 'fake_pod_name',
            'az_name': 'fake_az'
        }
        api.create_pod(self.context, pod_dict)

        pod = api.get_pod_by_name(self.context, pod_dict['pod_name'] + '1')
        self.assertEqual(pod, None)

        pod = api.get_pod_by_name(self.context, pod_dict['pod_name'])
        self.assertEqual(pod['pod_id'], pod_dict['pod_id'])
        self.assertEqual(pod['pod_name'], pod_dict['pod_name'])
        self.assertEqual(pod['az_name'], pod_dict['az_name'])

        config_dict = {
            'service_id': 'fake_service_id',
            'pod_id': 'fake_pod_id',
            'service_type': cons.ST_CINDER,
            'service_url': 'http://127.0.0.1:8774/v2.1/$(tenant_id)s'
        }
        api.create_pod_service_configuration(self.context, config_dict)

        endpoint = hclient.get_pod_service_endpoint(
            self.context, pod_dict['pod_name'], config_dict['service_type'])
        self.assertEqual(endpoint, config_dict['service_url'])
Esempio n. 6
0
 def test_query(self):
     pod1 = {
         'pod_id': 'test_pod1_uuid',
         'pod_name': 'test_pod1',
         'pod_az_name': 'test_pod_az_name1',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az1_uuid'
     }
     pod2 = {
         'pod_id': 'test_pod2_uuid',
         'pod_name': 'test_pod2',
         'pod_az_name': 'test_pod_az_name2',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az2_uuid'
     }
     api.create_pod(self.context, pod1)
     api.create_pod(self.context, pod2)
     filters = [{
         'key': 'pod_name',
         'comparator': 'eq',
         'value': 'test_pod2'
     }]
     pods = api.list_pods(self.context, filters)
     self.assertEqual(len(pods), 1)
     self.assertEqual(pods[0], pod2)
     filters = [{
         'key': 'pod_name',
         'comparator': 'eq',
         'value': 'test_pod3'
     }]
     pods = api.list_pods(self.context, filters)
     self.assertEqual(len(pods), 0)
Esempio n. 7
0
 def test_delete(self):
     pod = {
         'pod_id': 'test_pod_uuid',
         'pod_name': 'test_pod',
         'az_name': 'test_az_uuid'
     }
     api.create_pod(self.context, pod)
     api.delete_pod(self.context, 'test_pod_uuid')
     self.assertRaises(exceptions.ResourceNotFound, api.get_pod,
                       self.context, 'test_pod_uuid')
Esempio n. 8
0
    def test_get_current_binding_and_pod(self):
        api.create_pod(self.context, self.b_pod_1)
        api.create_pod_binding(self.context, self.project_id,
                               self.b_pod_1['pod_id'])

        pod_b_1, pod_1 = self.pod_manager.get_current_binding_and_pod(
            self.context, self.az_name_1, self.project_id, pod_group='')
        binding_q = core.query_resource(self.context, models.PodBinding,
                                        [{
                                            'key': 'tenant_id',
                                            'comparator': 'eq',
                                            'value': self.project_id
                                        }], [])
        self.assertEqual(len(binding_q), 1)
        self.assertEqual(binding_q[0]['id'], pod_b_1['id'])

        pod_b_2, pod_2 = self.pod_manager.get_current_binding_and_pod(
            self.context, self.az_name_1, 'new_project_pm_1', pod_group='')
        binding_q = core.query_resource(self.context, models.PodBinding,
                                        [{
                                            'key': 'tenant_id',
                                            'comparator': 'eq',
                                            'value': 'new_project_pm_1'
                                        }], [])
        self.assertEqual(len(binding_q), 0)
        self.assertEqual(pod_b_2, None)
        self.assertEqual(pod_2, None)

        pod_b_3, pod_3 = self.pod_manager.get_current_binding_and_pod(
            self.context, 'unknown_az', self.project_id, pod_group='')
        binding_q = core.query_resource(self.context, models.PodBinding,
                                        [{
                                            'key': 'tenant_id',
                                            'comparator': 'eq',
                                            'value': self.project_id
                                        }], [])
        self.assertEqual(len(binding_q), 1)
        self.assertEqual(pod_b_3, None)
        self.assertEqual(pod_3, None)

        pod_b_4, pod_4 = self.pod_manager.get_current_binding_and_pod(
            self.context, self.az_name_1, self.project_id, pod_group='test')
        binding_q = core.query_resource(self.context, models.PodBinding,
                                        [{
                                            'key': 'tenant_id',
                                            'comparator': 'eq',
                                            'value': self.project_id
                                        }], [])
        self.assertEqual(len(binding_q), 1)
        self.assertEqual(pod_b_4['id'], binding_q[0]['id'])
        self.assertEqual(pod_4, None)
Esempio n. 9
0
    def test_get_pod_service_ctx(self):
        pod_dict = {
            'pod_id': 'fake_pod_id',
            'pod_name': 'fake_pod_name',
            'az_name': 'fake_az'
        }

        config_dict = {
            'service_id': 'fake_service_id',
            'pod_id': 'fake_pod_id',
            'service_type': cons.ST_CINDER,
            'service_url': 'http://127.0.0.1:8774/v2.1/$(tenant_id)s'
        }
        t_url = 'http://127.0.0.1:8774/v2/my_tenant_id/volumes'
        api.create_pod(self.context, pod_dict)
        api.create_pod_service_configuration(self.context, config_dict)

        b_url = 'http://127.0.0.1:8774/v2.1/my_tenant_id/volumes'

        b_endpoint = hclient.get_pod_service_endpoint(self.context,
                                                      pod_dict['pod_name'],
                                                      cons.ST_CINDER)
        self.assertEqual(b_endpoint, config_dict['service_url'])

        b_ctx = hclient.get_pod_service_ctx(self.context, t_url,
                                            pod_dict['pod_name'],
                                            cons.ST_CINDER)
        self.assertEqual(b_ctx['t_ver'], 'v2')
        self.assertEqual(b_ctx['t_url'], t_url)
        self.assertEqual(b_ctx['b_ver'], 'v2.1')
        self.assertEqual(b_ctx['b_url'], b_url)

        # wrong pod name
        b_ctx = hclient.get_pod_service_ctx(self.context, t_url,
                                            pod_dict['pod_name'] + '1',
                                            cons.ST_CINDER)
        self.assertEqual(b_ctx['t_ver'], 'v2')
        self.assertEqual(b_ctx['t_url'], t_url)
        self.assertEqual(b_ctx['b_ver'], '')
        self.assertEqual(b_ctx['b_url'], '')

        # wrong service_type
        b_ctx = hclient.get_pod_service_ctx(self.context, t_url,
                                            pod_dict['pod_name'],
                                            cons.ST_CINDER + '1')
        self.assertEqual(b_ctx['t_ver'], 'v2')
        self.assertEqual(b_ctx['t_url'], t_url)
        self.assertEqual(b_ctx['b_ver'], '')
        self.assertEqual(b_ctx['b_url'], '')
Esempio n. 10
0
 def test_create_binding(self):
     api.create_pod(self.context, self.b_pod_2)
     flag = self.pod_manager.create_binding(self.context,
                                            'new_project_pm_2',
                                            self.b_pod_2['pod_id'])
     self.assertEqual(flag, True)
     binding_q = core.query_resource(self.context, models.PodBinding,
                                     [{
                                         'key': 'tenant_id',
                                         'comparator': 'eq',
                                         'value': 'new_project_pm_2'
                                     }], [])
     self.assertEqual(len(binding_q), 1)
     self.assertEqual(binding_q[0]['pod_id'], self.b_pod_2['pod_id'])
     self.assertEqual(binding_q[0]['tenant_id'], 'new_project_pm_2')
     self.assertEqual(binding_q[0]['is_binding'], True)
Esempio n. 11
0
 def test_update(self):
     pod = {
         'pod_id': 'test_pod_uuid',
         'pod_name': 'test_pod',
         'az_name': 'test_az1_uuid'
     }
     api.create_pod(self.context, pod)
     update_dict = {
         'pod_id': 'fake_uuid',
         'pod_name': 'test_pod2',
         'az_name': 'test_az2_uuid'
     }
     ret = api.update_pod(self.context, 'test_pod_uuid', update_dict)
     # primary key value will not be updated
     self.assertEqual(ret['pod_id'], 'test_pod_uuid')
     self.assertEqual(ret['pod_name'], 'test_pod2')
     self.assertEqual(ret['az_name'], 'test_az2_uuid')
Esempio n. 12
0
 def test_resource_routing_unique_key(self):
     pod = {
         'pod_id': 'test_pod1_uuid',
         'pod_name': 'test_pod1',
         'az_name': 'test_az1_uuid'
     }
     api.create_pod(self.context, pod)
     routing = {
         'top_id': 'top_uuid',
         'pod_id': 'test_pod1_uuid',
         'resource_type': 'port'
     }
     with self.context.session.begin():
         core.create_resource(self.context, models.ResourceRouting, routing)
     self.assertRaises(oslo_db.exception.DBDuplicateEntry,
                       core.create_resource, self.context,
                       models.ResourceRouting, routing)
Esempio n. 13
0
    def test_get_next_bottom_pod(self):
        next_pod = api.get_next_bottom_pod(self.context)
        self.assertIsNone(next_pod)
        pods = []
        for i in xrange(5):
            pod = {
                'pod_id': 'test_pod_uuid_%d' % i,
                'pod_name': 'test_pod_%d' % i,
                'pod_az_name': 'test_pod_az_name_%d' % i,
                'dc_name': 'test_dc_name_%d' % i,
                'az_name': 'test_az_uuid_%d' % i,
            }
            api.create_pod(self.context, pod)
            pods.append(pod)
        next_pod = api.get_next_bottom_pod(self.context)
        self.assertEqual(next_pod, pods[0])

        next_pod = api.get_next_bottom_pod(self.context,
                                           current_pod_id='test_pod_uuid_2')
        self.assertEqual(next_pod, pods[3])

        next_pod = api.get_next_bottom_pod(self.context,
                                           current_pod_id='test_pod_uuid_4')
        self.assertIsNone(next_pod)
Esempio n. 14
0
    def _init_db(self):
        core.initialize()
        core.ModelBase.metadata.create_all(core.get_engine())
        # enforce foreign key constraint for sqlite
        core.get_engine().execute('pragma foreign_keys=on')
        self.context = context.Context()

        pod_dict = {
            'pod_id': 'fake_pod_id',
            'pod_name': 'fake_pod_name',
            'az_name': FAKE_AZ
        }

        config_dict = {
            'service_id': 'fake_service_id',
            'pod_id': 'fake_pod_id',
            'service_type': cons.ST_NOVA,
            'service_url': 'http://127.0.0.1:8774/v2/$(tenant_id)s'
        }

        pod_dict2 = {
            'pod_id': 'fake_pod_id' + '2',
            'pod_name': 'fake_pod_name' + '2',
            'az_name': FAKE_AZ + '2'
        }

        config_dict2 = {
            'service_id': 'fake_service_id' + '2',
            'pod_id': 'fake_pod_id' + '2',
            'service_type': cons.ST_CINDER,
            'service_url': 'http://10.0.0.2:8774/v2/$(tenant_id)s'
        }

        top_pod = {
            'pod_id': 'fake_top_pod_id',
            'pod_name': 'RegionOne',
            'az_name': ''
        }

        top_config = {
            'service_id': 'fake_top_service_id',
            'pod_id': 'fake_top_pod_id',
            'service_type': cons.ST_CINDER,
            'service_url': 'http://127.0.0.1:19998/v2/$(tenant_id)s'
        }

        db_api.create_pod(self.context, pod_dict)
        db_api.create_pod(self.context, pod_dict2)
        db_api.create_pod(self.context, top_pod)
        db_api.create_pod_service_configuration(self.context, config_dict)
        db_api.create_pod_service_configuration(self.context, config_dict2)
        db_api.create_pod_service_configuration(self.context, top_config)
Esempio n. 15
0
    def setUp(self):
        core.initialize()
        core.ModelBase.metadata.create_all(core.get_engine())
        # enforce foreign key constraint for sqlite
        core.get_engine().execute('pragma foreign_keys=on')
        self.context = context.Context()

        top_pod = {
            'pod_id': FAKE_TOP_ID,
            'pod_name': FAKE_TOP_NAME,
            'az_name': ''
        }

        config_dict_top = {
            'service_id': FAKE_TOP_SERVICE_ID,
            'pod_id': FAKE_TOP_ID,
            'service_type': FAKE_SERVICE_TYPE,
            'service_url': FAKE_TOP_ENDPOINT
        }

        pod_dict = {
            'pod_id': FAKE_SITE_ID,
            'pod_name': FAKE_SITE_NAME,
            'az_name': FAKE_AZ
        }

        pod_dict2 = {
            'pod_id': FAKE_SITE_ID_2,
            'pod_name': FAKE_SITE_NAME_2,
            'az_name': FAKE_AZ
        }

        config_dict = {
            'service_id': FAKE_SERVICE_ID,
            'pod_id': FAKE_SITE_ID,
            'service_type': FAKE_SERVICE_TYPE,
            'service_url': FAKE_SERVICE_ENDPOINT
        }

        config_dict2 = {
            'service_id': FAKE_SERVICE_ID_2,
            'pod_id': FAKE_SITE_ID_2,
            'service_type': FAKE_SERVICE_TYPE,
            'service_url': FAKE_SERVICE_ENDPOINT_2
        }

        api.create_pod(self.context, pod_dict)
        api.create_pod(self.context, pod_dict2)
        api.create_pod(self.context, top_pod)
        api.create_pod_service_configuration(self.context, config_dict)
        api.create_pod_service_configuration(self.context, config_dict2)
        api.create_pod_service_configuration(self.context, config_dict_top)
Esempio n. 16
0
    def test_create(self):
        pod = {
            'pod_id': 'test_pod_uuid',
            'pod_name': 'test_pod',
            'pod_az_name': 'test_pod_az_name',
            'dc_name': 'test_dc_name',
            'az_name': 'test_az_uuid'
        }
        pod_ret = api.create_pod(self.context, pod)
        self.assertEqual(pod_ret, pod)

        configuration = {
            'service_id': 'test_config_uuid',
            'pod_id': 'test_pod_uuid',
            'service_type': 'nova',
            'service_url': 'http://test_url'
        }
        config_ret = api.create_pod_service_configuration(
            self.context, configuration)
        self.assertEqual(config_ret, configuration)
Esempio n. 17
0
 def _prepare_pod(self, bottom_pod_num=1):
     t_pod = {'pod_id': 't_pod_uuid', 'pod_name': 't_region',
              'az_name': ''}
     api.create_pod(self.context, t_pod)
     b_pods = []
     if bottom_pod_num == 1:
         b_pod = {'pod_id': 'b_pod_uuid', 'pod_name': 'b_region',
                  'az_name': 'b_az'}
         api.create_pod(self.context, b_pod)
         b_pods.append(b_pod)
     else:
         for i in xrange(1, bottom_pod_num + 1):
             b_pod = {'pod_id': 'b_pod_%d_uuid' % i,
                      'pod_name': 'b_region_%d' % i,
                      'az_name': 'b_az_%d' % i}
             api.create_pod(self.context, b_pod)
             b_pods.append(b_pod)
     return t_pod, b_pods
Esempio n. 18
0
    def test_get_bottom_mappings_by_tenant_pod(self):
        for i in xrange(3):
            pod = {
                'pod_id': 'test_pod_uuid_%d' % i,
                'pod_name': 'test_pod_%d' % i,
                'az_name': 'test_az_uuid_%d' % i
            }
            api.create_pod(self.context, pod)
        routes = [{
            'route': {
                'top_id': 'top_uuid',
                'pod_id': 'test_pod_uuid_0',
                'project_id': 'test_project_uuid_0',
                'resource_type': 'port'
            },
        }, {
            'route': {
                'top_id': 'top_uuid_0',
                'bottom_id': 'top_uuid_0',
                'pod_id': 'test_pod_uuid_0',
                'project_id': 'test_project_uuid_0',
                'resource_type': 'port'
            },
        }, {
            'route': {
                'top_id': 'top_uuid_1',
                'bottom_id': 'top_uuid_1',
                'pod_id': 'test_pod_uuid_0',
                'project_id': 'test_project_uuid_0',
                'resource_type': 'port'
            },
        }, {
            'route': {
                'top_id': 'top_uuid_2',
                'bottom_id': 'top_uuid_2',
                'pod_id': 'test_pod_uuid_0',
                'project_id': 'test_project_uuid_1',
                'resource_type': 'port'
            },
        }, {
            'route': {
                'top_id': 'top_uuid_3',
                'bottom_id': 'top_uuid_3',
                'pod_id': 'test_pod_uuid_1',
                'project_id': 'test_project_uuid_1',
                'resource_type': 'port'
            },
        }]

        with self.context.session.begin():
            for route in routes:
                core.create_resource(self.context, models.ResourceRouting,
                                     route['route'])

        routings = api.get_bottom_mappings_by_tenant_pod(
            self.context, 'test_project_uuid_0', 'test_pod_uuid_0', 'port')
        self.assertEqual(len(routings), 2)
        self.assertEqual(routings['top_uuid_0']['top_id'], 'top_uuid_0')
        self.assertEqual(routings['top_uuid_1']['top_id'], 'top_uuid_1')

        routings = api.get_bottom_mappings_by_tenant_pod(
            self.context, 'test_project_uuid_1', 'test_pod_uuid_0', 'port')
        self.assertEqual(len(routings), 1)
        self.assertEqual(routings['top_uuid_2']['top_id'], 'top_uuid_2')
        self.assertEqual(routings['top_uuid_2']['bottom_id'], 'top_uuid_2')

        routings = api.get_bottom_mappings_by_tenant_pod(
            self.context, 'test_project_uuid_1', 'test_pod_uuid_1', 'port')
        self.assertEqual(len(routings), 1)
        self.assertEqual(routings['top_uuid_3']['top_id'], 'top_uuid_3')
        self.assertEqual(routings['top_uuid_3']['bottom_id'], 'top_uuid_3')