def _create_dummy_endpoint(self, add_clean_up=True): region_id = data_utils.rand_name('TestRegion') service_name = self._create_dummy_service() public_url = data_utils.rand_url() admin_url = data_utils.rand_url() internal_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint create ' '--publicurl %(publicurl)s ' '--adminurl %(adminurl)s ' '--internalurl %(internalurl)s ' '--region %(region)s ' '%(service)s' % {'publicurl': public_url, 'adminurl': admin_url, 'internalurl': internal_url, 'region': region_id, 'service': service_name}) endpoint = self.parse_show_as_object(raw_output) if add_clean_up: self.addCleanup( self.openstack, 'endpoint delete %s' % endpoint['id']) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) return endpoint['id']
def test_update_endpoint(self): # Creating an endpoint so as to check update endpoint # with new values region1 = data_utils.rand_name('region') url1 = data_utils.rand_url() interface1 = 'public' endpoint_for_update =\ self.client.create_endpoint(self.service_id, interface1, url1, region=region1, enabled=True) self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id']) # Creating service so as update endpoint with new service ID s_name = data_utils.rand_name('service') s_type = data_utils.rand_name('type') s_description = data_utils.rand_name('description') service2 =\ self.service_client.create_service(s_name, s_type, description=s_description) self.service_ids.append(service2['id']) # Updating endpoint with new values region2 = data_utils.rand_name('region') url2 = data_utils.rand_url() interface2 = 'internal' endpoint = \ self.client.update_endpoint(endpoint_for_update['id'], service_id=service2['id'], interface=interface2, url=url2, region=region2, enabled=False) # Asserting if the attributes of endpoint are updated self.assertEqual(service2['id'], endpoint['service_id']) self.assertEqual(interface2, endpoint['interface']) self.assertEqual(url2, endpoint['url']) self.assertEqual(region2, endpoint['region']) self.assertEqual(False, endpoint['enabled'])
def test_update_endpoint(self): # Creating an endpoint so as to check update endpoint # with new values region1 = data_utils.rand_name('region') url1 = data_utils.rand_url() interface1 = 'public' endpoint_for_update =\ self.client.create_endpoint(self.service_id, interface1, url1, region=region1, enabled=True) self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id']) # Creating service so as update endpoint with new service ID s_name = data_utils.rand_name('service') s_type = data_utils.rand_name('type') s_description = data_utils.rand_name('description') service2 =\ self.service_client.create_service(s_name, s_type, description=s_description) self.service_ids.append(service2['id']) # Updating endpoint with new values region2 = data_utils.rand_name('region') url2 = data_utils.rand_url() interface2 = 'internal' endpoint = \ self.client.update_endpoint(endpoint_for_update['id'], service_id=service2['id'], interface=interface2, url=url2, region=region2, enabled=False) # Asserting if the attributes of endpoint are updated self.assertEqual(service2['id'], endpoint['service_id']) self.assertEqual(interface2, endpoint['interface']) self.assertEqual(url2, endpoint['url']) self.assertEqual(region2, endpoint['region']) self.assertEqual('false', str(endpoint['enabled']).lower())
def _create_dummy_endpoint(self, add_clean_up=True): region_id = data_utils.rand_name('TestRegion') service_name = self._create_dummy_service() public_url = data_utils.rand_url() admin_url = data_utils.rand_url() internal_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint create ' '--publicurl %(publicurl)s ' '--adminurl %(adminurl)s ' '--internalurl %(internalurl)s ' '--region %(region)s ' '%(service)s' % { 'publicurl': public_url, 'adminurl': admin_url, 'internalurl': internal_url, 'region': region_id, 'service': service_name }) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) endpoint = self.parse_show_as_object(raw_output) if add_clean_up: self.addCleanup(self.openstack, 'endpoint delete %s' % endpoint['id']) return endpoint['id']
def test_create_with_enabled_True(self): # Enabled should be a boolean, not a string like 'True' interface = 'public' url = data_utils.rand_url() region = data_utils.rand_name('region') self.assertRaises(lib_exc.BadRequest, self.client.create_endpoint, self.service_id, interface, url, region=region, force_enabled='True')
def _assert_update_raises_bad_request(self, enabled): # Create an endpoint region1 = data_utils.rand_name('region') url1 = data_utils.rand_url() interface1 = 'public' endpoint_for_update = ( self.client.create_endpoint(self.service_id, interface1, url1, region=region1, enabled=True)) self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id']) self.assertRaises(lib_exc.BadRequest, self.client.update_endpoint, endpoint_for_update['id'], force_enabled=enabled)
def test_create_with_enabled_False(self): # Enabled should be a boolean, not a string like 'False' interface = "public" url = data_utils.rand_url() region = data_utils.rand_name("region") self.assertRaises( lib_exc.BadRequest, self.client.create_endpoint, self.service_id, interface, url, region=region, force_enabled="False", )
def test_endpoint_set(self): endpoint_id = self._create_dummy_endpoint() new_endpoint_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint set ' '--interface %(interface)s ' '--url %(url)s ' '--disable ' '%(endpoint_id)s' % {'interface': 'admin', 'url': new_endpoint_url, 'endpoint_id': endpoint_id}) self.assertEqual(0, len(raw_output)) raw_output = self.openstack('endpoint show %s' % endpoint_id) endpoint = self.parse_show_as_object(raw_output) self.assertEqual('admin', endpoint['interface']) self.assertEqual(new_endpoint_url, endpoint['url']) self.assertEqual('False', endpoint['enabled'])
def _assert_update_raises_bad_request(self, enabled): # Create an endpoint region1 = data_utils.rand_name('region') url1 = data_utils.rand_url() interface1 = 'public' endpoint_for_update = (self.client.create_endpoint(self.service_id, interface1, url1, region=region1, enabled=True)) self.addCleanup(self.client.delete_endpoint, endpoint_for_update['id']) self.assertRaises(lib_exc.BadRequest, self.client.update_endpoint, endpoint_for_update['id'], force_enabled=enabled)
def test_endpoint_set(self): endpoint_id = self._create_dummy_endpoint() new_endpoint_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint set ' '--interface %(interface)s ' '--url %(url)s ' '--disable ' '%(endpoint_id)s' % { 'interface': 'admin', 'url': new_endpoint_url, 'endpoint_id': endpoint_id }) self.assertEqual(0, len(raw_output)) raw_output = self.openstack('endpoint show %s' % endpoint_id) endpoint = self.parse_show_as_object(raw_output) self.assertEqual('admin', endpoint['interface']) self.assertEqual(new_endpoint_url, endpoint['url']) self.assertEqual('False', endpoint['enabled'])
def resource_setup(cls): super(EndPointsTestJSON, cls).resource_setup() cls.service_ids = list() s_name = data_utils.rand_name('service') s_type = data_utils.rand_name('type') s_description = data_utils.rand_name('description') cls.service_data =\ cls.service_client.create_service(s_name, s_type, description=s_description) cls.service_id = cls.service_data['id'] cls.service_ids.append(cls.service_id) # Create endpoints so as to use for LIST and GET test cases cls.setup_endpoints = list() for i in range(2): region = data_utils.rand_name('region') url = data_utils.rand_url() interface = 'public' endpoint = cls.client.create_endpoint( cls.service_id, interface, url, region=region, enabled=True) cls.setup_endpoints.append(endpoint)
def test_create_list_delete_endpoint(self): region = data_utils.rand_name('region') url = data_utils.rand_url() interface = 'public' endpoint =\ self.client.create_endpoint(self.service_id, interface, url, region=region, enabled=True) # Asserting Create Endpoint response body self.assertIn('id', endpoint) self.assertEqual(region, endpoint['region']) self.assertEqual(url, endpoint['url']) # Checking if created endpoint is present in the list of endpoints fetched_endpoints = self.client.list_endpoints() fetched_endpoints_id = [e['id'] for e in fetched_endpoints] self.assertIn(endpoint['id'], fetched_endpoints_id) # Deleting the endpoint created in this method self.client.delete_endpoint(endpoint['id']) # Checking whether endpoint is deleted successfully fetched_endpoints = self.client.list_endpoints() fetched_endpoints_id = [e['id'] for e in fetched_endpoints] self.assertNotIn(endpoint['id'], fetched_endpoints_id)
def _create_dummy_region(self, parent_region=None, add_clean_up=True): region_id = data_utils.rand_name('TestRegion') description = data_utils.rand_name('description') url = data_utils.rand_url() parent_region_arg = '' if parent_region is not None: parent_region_arg = '--parent-region %s' % parent_region raw_output = self.openstack( 'region create ' '%(parent_region_arg)s ' '--description %(description)s ' '--url %(url)s ' '%(id)s' % {'parent_region_arg': parent_region_arg, 'description': description, 'url': url, 'id': region_id}) items = self.parse_show(raw_output) self.assert_show_fields(items, self.REGION_FIELDS) if add_clean_up: self.addCleanup(self.openstack, 'region delete %s' % region_id) return region_id
def _create_dummy_endpoint(self, interface='public', add_clean_up=True): region_id = self._create_dummy_region() service_name = self._create_dummy_service() endpoint_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint create ' '--region %(region)s ' '--enable ' '%(service)s ' '%(interface)s ' '%(url)s' % {'region': region_id, 'service': service_name, 'interface': interface, 'url': endpoint_url}) endpoint = self.parse_show_as_object(raw_output) if add_clean_up: self.addCleanup( self.openstack, 'endpoint delete %s' % endpoint['id']) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) return endpoint['id']
def _create_dummy_endpoint(self, interface='public', add_clean_up=True): region_id = self._create_dummy_region() service_name = self._create_dummy_service() endpoint_url = data_utils.rand_url() raw_output = self.openstack( 'endpoint create ' '--region %(region)s ' '--enable ' '%(service)s ' '%(interface)s ' '%(url)s' % {'region': region_id, 'service': service_name, 'interface': interface, 'url': endpoint_url}) items = self.parse_show(raw_output) self.assert_show_fields(items, self.ENDPOINT_FIELDS) endpoint = self.parse_show_as_object(raw_output) if add_clean_up: self.addCleanup( self.openstack, 'endpoint delete %s' % endpoint['id']) return endpoint['id']
def test_rand_url(self): actual = data_utils.rand_url() self.assertIsInstance(actual, str) self.assertRegexpMatches(actual, "^https://url-[0-9]*\.com$") actual2 = data_utils.rand_url() self.assertNotEqual(actual, actual2)