Migrate dns to new discovery method
Change-Id: I66cdb189a87e94df35fbdb720c48e59f24ca51cb
This commit is contained in:
parent
a45848d5b9
commit
641073bba9
|
@ -403,7 +403,11 @@ class OpenStackCloud(
|
|||
@property
|
||||
def _dns_client(self):
|
||||
if 'dns' not in self._raw_clients:
|
||||
self._raw_clients['dns'] = self._get_raw_client('dns')
|
||||
dns_client = self._get_raw_client('dns')
|
||||
dns_url = self._discover_endpoint(
|
||||
'dns', version_required=True)
|
||||
dns_client.endpoint_override = dns_url
|
||||
self._raw_clients['dns'] = dns_client
|
||||
return self._raw_clients['dns']
|
||||
|
||||
@property
|
||||
|
@ -6948,7 +6952,7 @@ class OpenStackCloud(
|
|||
|
||||
"""
|
||||
return self._dns_client.get(
|
||||
"/v2/zones",
|
||||
"/zones",
|
||||
error_message="Error fetching zones list")
|
||||
|
||||
def get_zone(self, name_or_id, filters=None):
|
||||
|
@ -7012,7 +7016,7 @@ class OpenStackCloud(
|
|||
zone["masters"] = masters
|
||||
|
||||
return self._dns_client.post(
|
||||
"/v2/zones", json=zone,
|
||||
"/zones", json=zone,
|
||||
error_message="Unable to create zone {name}".format(name=name))
|
||||
|
||||
@_utils.valid_kwargs('email', 'description', 'ttl', 'masters')
|
||||
|
@ -7037,7 +7041,7 @@ class OpenStackCloud(
|
|||
"Zone %s not found." % name_or_id)
|
||||
|
||||
return self._dns_client.patch(
|
||||
"/v2/zones/{zone_id}".format(zone_id=zone['id']), json=kwargs,
|
||||
"/zones/{zone_id}".format(zone_id=zone['id']), json=kwargs,
|
||||
error_message="Error updating zone {0}".format(name_or_id))
|
||||
|
||||
def delete_zone(self, name_or_id):
|
||||
|
@ -7056,7 +7060,7 @@ class OpenStackCloud(
|
|||
return False
|
||||
|
||||
return self._dns_client.delete(
|
||||
"/v2/zones/{zone_id}".format(zone_id=zone['id']),
|
||||
"/zones/{zone_id}".format(zone_id=zone['id']),
|
||||
error_message="Error deleting zone {0}".format(name_or_id))
|
||||
|
||||
return True
|
||||
|
@ -7070,7 +7074,7 @@ class OpenStackCloud(
|
|||
|
||||
"""
|
||||
return self._dns_client.get(
|
||||
"/v2/zones/{zone_id}/recordsets".format(zone_id=zone),
|
||||
"/zones/{zone_id}/recordsets".format(zone_id=zone),
|
||||
error_message="Error fetching recordsets list")
|
||||
|
||||
def get_recordset(self, zone, name_or_id):
|
||||
|
@ -7085,7 +7089,7 @@ class OpenStackCloud(
|
|||
"""
|
||||
try:
|
||||
return self._dns_client.get(
|
||||
"/v2/zones/{zone_id}/recordsets/{recordset_id}".format(
|
||||
"/zones/{zone_id}/recordsets/{recordset_id}".format(
|
||||
zone_id=zone, recordset_id=name_or_id),
|
||||
error_message="Error fetching recordset")
|
||||
except Exception:
|
||||
|
@ -7131,7 +7135,7 @@ class OpenStackCloud(
|
|||
body['ttl'] = ttl
|
||||
|
||||
return self._dns_client.post(
|
||||
"/v2/zones/{zone_id}/recordsets".format(zone_id=zone),
|
||||
"/zones/{zone_id}/recordsets".format(zone_id=zone),
|
||||
json=body,
|
||||
error_message="Error creating recordset {name}".format(name=name))
|
||||
|
||||
|
@ -7160,7 +7164,7 @@ class OpenStackCloud(
|
|||
"Recordset %s not found." % name_or_id)
|
||||
|
||||
new_recordset = self._dns_client.put(
|
||||
"/v2/zones/{zone_id}/recordsets/{recordset_id}".format(
|
||||
"/zones/{zone_id}/recordsets/{recordset_id}".format(
|
||||
zone_id=zone_obj['id'], recordset_id=name_or_id), json=kwargs,
|
||||
error_message="Error updating recordset {0}".format(name_or_id))
|
||||
|
||||
|
@ -7188,7 +7192,7 @@ class OpenStackCloud(
|
|||
return False
|
||||
|
||||
self._dns_client.delete(
|
||||
"/v2/zones/{zone_id}/recordsets/{recordset_id}".format(
|
||||
"/zones/{zone_id}/recordsets/{recordset_id}".format(
|
||||
zone_id=zone['id'], recordset_id=name_or_id),
|
||||
error_message="Error deleting recordset {0}".format(name_or_id))
|
||||
|
||||
|
|
|
@ -477,6 +477,12 @@ class RequestsMockTestCase(BaseTestCase):
|
|||
status_code=300,
|
||||
text=open(discovery_fixture, 'r').read())
|
||||
|
||||
def get_designate_discovery_mock_dict(self):
|
||||
discovery_fixture = os.path.join(
|
||||
self.fixtures_directory, "dns.json")
|
||||
return dict(method='GET', uri="https://dns.example.com/",
|
||||
text=open(discovery_fixture, 'r').read())
|
||||
|
||||
def use_glance(self, image_version_json='image-version.json'):
|
||||
# NOTE(notmorgan): This method is only meant to be used in "setUp"
|
||||
# where the ordering of the url being registered is tightly controlled
|
||||
|
@ -486,6 +492,15 @@ class RequestsMockTestCase(BaseTestCase):
|
|||
self.__do_register_uris([
|
||||
self.get_glance_discovery_mock_dict(image_version_json)])
|
||||
|
||||
def use_designate(self):
|
||||
# NOTE(slaweq): This method is only meant to be used in "setUp"
|
||||
# where the ordering of the url being registered is tightly controlled
|
||||
# if the functionality of .use_designate is meant to be used during an
|
||||
# actual test case, use .get_designate_discovery_mock and apply to the
|
||||
# right location in the mock_uris when calling .register_uris
|
||||
self.__do_register_uris([
|
||||
self.get_designate_discovery_mock_dict()])
|
||||
|
||||
def register_uris(self, uri_mock_list=None):
|
||||
"""Mock a list of URIs and responses via requests mock.
|
||||
|
||||
|
|
|
@ -43,6 +43,10 @@ new_recordset['zone'] = recordset_zone
|
|||
|
||||
class TestRecordset(base.RequestsMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRecordset, self).setUp()
|
||||
self.use_designate()
|
||||
|
||||
def test_create_recordset(self):
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
|
|
|
@ -31,6 +31,10 @@ new_zone_dict['id'] = '1'
|
|||
|
||||
class TestZone(base.RequestsMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestZone, self).setUp()
|
||||
self.use_designate()
|
||||
|
||||
def test_create_zone(self):
|
||||
self.register_uris([
|
||||
dict(method='POST',
|
||||
|
|
Loading…
Reference in New Issue