예제 #1
0
    def create_recordset(self,
                         zone_uuid,
                         recordset_data,
                         params=None,
                         wait_until=False):
        """Create a recordset for the specified zone.

        :param zone_uuid: Unique identifier of the zone in UUID format..
        :param recordset_data: A dictionary that represents the recordset
                               data.
        :param params: A Python dict that represents the query paramaters to
                       include in the request URI.
        :return: A tuple with the server response and the created zone.
        """
        resp, body = self._create_request(
            "/zones/{0}/recordsets".format(zone_uuid),
            params=params,
            data=recordset_data)

        # Create Recordset should Return a HTTP 202
        self.expected_success(202, resp.status)

        if wait_until:
            waiters.wait_for_recordset_status(self, body['id'], wait_until)

        return resp, body
    def test_create_SPF_with(self, data):
        post_model = data_utils.rand_spf_recordset(self.zone['name'], data)
        recordset = self.create_recordset(post_model)

        waiters.wait_for_recordset_status(self.recordset_client,
                                          self.zone['id'], recordset['id'],
                                          'ACTIVE')
예제 #3
0
    def test_show_recordsets_invalid_ids(self):

        LOG.info('Create a Recordset')
        recordset_data = dns_data_utils.rand_recordset_data(
            record_type='A', zone_name=self.zone['name'])
        resp, body = self.client.create_recordset(self.zone['id'],
                                                  recordset_data)
        self.addCleanup(self.wait_recordset_delete, self.client,
                        self.zone['id'], body['id'])
        self.assertEqual(const.PENDING, body['status'],
                         'Failed, expected status is PENDING')
        LOG.info('Wait until the recordset is active')
        waiters.wait_for_recordset_status(self.client, self.zone['id'],
                                          body['id'], const.ACTIVE)

        LOG.info('Ensure 404 NotFound status code is received if '
                 'recordset ID is invalid.')
        self.assertRaises(
            lib_exc.NotFound, lambda: self.client.show_recordset(
                zone_uuid=self.zone['id'],
                recordset_uuid=data_utils.rand_uuid()))

        LOG.info('Ensure 404 NotFound status code is received if '
                 'zone ID is invalid.')
        self.assertRaises(
            lib_exc.NotFound, lambda: self.client.show_recordset(
                zone_uuid=data_utils.rand_uuid(), recordset_uuid=body['id']))
예제 #4
0
    def test_all_recordset_types_exist_in_show_zonefile(self):
        recorsets_data_file = os.path.join(os.path.dirname(__file__),
                                           'recordset_data.json')

        if not os.path.exists(recorsets_data_file):
            raise self.skipException(f"Could not find {recorsets_data_file}")

        file = open(recorsets_data_file, "r")
        load_file = json.loads(file.read())
        file.close()

        LOG.info('Create a zone')
        zone_name = dns_data_utils.rand_zone_name(
            name="all_recordset_types_exist", suffix=self.tld_name)
        zone = self.zones_client.create_zone(name=zone_name,
                                             wait_until=const.ACTIVE)[1]
        self.addCleanup(self.wait_zone_delete, self.zones_client, zone['id'])

        created_records = []
        for record_data in load_file.values():
            recordset_data = {
                'name': f"{record_data['name']}.{zone['name']}",
                'type': record_data['type'],
                'records': record_data['records'],
            }
            try:
                LOG.info('Create a Recordset')
                recordset = self.recordset_client.create_recordset(
                    zone['id'], recordset_data)[1]
                self.addCleanup(self.wait_recordset_delete,
                                self.recordset_client, zone['id'],
                                recordset['id'])
                created_records.append(recordset['records'])
                waiters.wait_for_recordset_status(self.recordset_client,
                                                  zone['id'], recordset['id'],
                                                  const.ACTIVE)
            except Exception as err:
                LOG.warning(f"Record of type {recordset['type']} could not be"
                            f" created and failed with error: {err}")

        LOG.info('Create a zone export')
        zone_export = self.client.create_zone_export(
            zone['id'], wait_until=const.COMPLETE)[1]
        self.addCleanup(self.client.delete_zone_export, zone_export['id'])

        LOG.info('Show exported zonefile')
        created_zonefile = self.client.show_exported_zonefile(
            zone_export['id'])[1]

        file_records = [item.data for item in created_zonefile.records]
        for record in created_records:
            for r in record:
                self.assertIn(r, file_records,
                              f"Failed, missing record: {r} in zone file")
예제 #5
0
 def test_create_A_recordset_multiply_ips(self):
     LOG.info('Create A type Recordset using a list of random IPs')
     recordset_data = dns_data_utils.rand_a_recordset(
         zone_name=self.zone['name'],
         ips=[dns_data_utils.rand_ip() for _ in range(10)])
     resp, body = self.client.create_recordset(self.zone['id'],
                                               recordset_data)
     self.addCleanup(self.wait_recordset_delete, self.client,
                     self.zone['id'], body['id'])
     LOG.info('Ensure we respond with PENDING')
     self.assertEqual(const.PENDING, body['status'])
     LOG.info('Wait until the recordset is active')
     waiters.wait_for_recordset_status(self.client, self.zone['id'],
                                       body['id'], const.ACTIVE)
예제 #6
0
    def test_create_and_delete_records_on_existing_zone(
            self, name, type, records):
        if name is not None:
            recordset_name = name + "." + self.zone['name']

        else:
            recordset_name = self.zone['name']

        recordset_data = {
            'name': recordset_name,
            'type': type,
            'records': records,
        }

        LOG.info('Create a Recordset on the existing zone')
        _, recordset = self.recordset_client.create_recordset(
            self.zone['id'], recordset_data)
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        self.recordset_client.delete_recordset,
                        self.zone['id'], recordset['id'])

        LOG.info('Ensure we respond with PENDING')
        self.assertEqual('PENDING', recordset['status'])

        LOG.info('Wait until the recordset is active')
        waiters.wait_for_recordset_status(self.recordset_client,
                                          self.zone['id'], recordset['id'],
                                          'ACTIVE')

        LOG.info('Delete the recordset')
        _, body = self.recordset_client.delete_recordset(
            self.zone['id'], recordset['id'])

        LOG.info('Ensure we respond with DELETE+PENDING')
        self.assertEqual('DELETE', body['action'])
        self.assertEqual('PENDING', body['status'])

        LOG.info('Ensure successful deletion of Recordset')
        self.assertRaises(
            lib_exc.NotFound, lambda: self.recordset_client.show_recordset(
                self.zone['id'], recordset['id']))
    def test_create_and_delete_records_on_existing_zone(self, name,
                                                        type, records):
        if name is not None:
            recordset_name = name + "." + self.zone['name']

        else:
            recordset_name = self.zone['name']

        recordset_data = {
            'name': recordset_name,
            'type': type,
            'records': records,
        }

        LOG.info('Create a Recordset on the existing zone')
        _, recordset = self.recordset_client.create_recordset(
            self.zone['id'], recordset_data)
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        self.recordset_client.delete_recordset,
                        self.zone['id'], recordset['id'])

        LOG.info('Ensure we respond with PENDING')
        self.assertEqual('PENDING', recordset['status'])

        LOG.info('Wait until the recordset is active')
        waiters.wait_for_recordset_status(self.recordset_client,
                                          self.zone['id'], recordset['id'],
                                          'ACTIVE')

        LOG.info('Delete the recordset')
        _, body = self.recordset_client.delete_recordset(self.zone['id'],
                                                         recordset['id'])

        LOG.info('Ensure we respond with DELETE+PENDING')
        self.assertEqual('DELETE', body['action'])
        self.assertEqual('PENDING', body['status'])

        LOG.info('Ensure successful deletion of Recordset')
        self.assertRaises(lib_exc.NotFound,
                          lambda: self.recordset_client.show_recordset(
                              self.zone['id'], recordset['id']))
    def create_recordset(self, zone_uuid, recordset_data,
                         params=None, wait_until=False):
        """Create a recordset for the specified zone.

        :param zone_uuid: Unique identifier of the zone in UUID format..
        :param recordset_data: A dictionary that represents the recordset
                                data.
        :param params: A Python dict that represents the query paramaters to
                       include in the request URI.
        :return: A tuple with the server response and the created zone.
        """
        resp, body = self._create_request(
            "/zones/{0}/recordsets".format(zone_uuid), params=params,
            object_dict=recordset_data)

        # Create Recordset should Return a HTTP 202
        self.expected_success(202, resp.status)

        if wait_until:
            waiters.wait_for_recordset_status(self, body['id'], wait_until)

        return resp, body
예제 #9
0
    def test_show_recordsets_impersonate_another_project(self):

        LOG.info('Create a Recordset')
        recordset_data = dns_data_utils.rand_recordset_data(
            record_type='A', zone_name=self.zone['name'])
        resp, body = self.client.create_recordset(self.zone['id'],
                                                  recordset_data)
        self.addCleanup(self.wait_recordset_delete, self.client,
                        self.zone['id'], body['id'])
        self.assertEqual(const.PENDING, body['status'],
                         'Failed, expected status is PENDING')
        LOG.info('Wait until the recordset is active')
        waiters.wait_for_recordset_status(self.client, self.zone['id'],
                                          body['id'], const.ACTIVE)

        LOG.info('Re-Fetch the Recordset as Alt tenant with '
                 '"x-auth-sudo-project-id" HTTP header included in request. '
                 'Expected: 403')
        self.assertRaises(
            lib_exc.Forbidden, lambda: self.alt_client.show_recordset(
                self.zone['id'],
                body['id'],
                headers={'x-auth-sudo-project-id': body['project_id']}))

        LOG.info('Re-Fetch the Recordset as Admin tenant without '
                 '"x-auth-sudo-project-id" HTTP header. Expected: 404')
        self.assertRaises(
            lib_exc.NotFound, lambda: self.admin_client.show_recordset(
                self.zone['id'], body['id']))

        record = self.admin_client.show_recordset(
            self.zone['id'],
            body['id'],
            headers={'x-auth-sudo-project-id': body['project_id']})[1]

        LOG.info('Ensure the fetched response matches the expected one')
        self.assertExpected(body, record,
                            self.excluded_keys + ['action', 'status'])
예제 #10
0
    def _create_client_recordset(self, clients_list):
        """Create a zone and asoociated recordset using given credentials
        :param clients_list: supported credentials are: 'primary' and 'alt'.
        :return: dictionary of created recordsets.
        """
        recordsets_created = {}
        for client in clients_list:
            if client == 'primary':
                # Create a zone and wait till it's ACTIVE
                zone_name = dns_data_utils.rand_zone_name(name="primary",
                                                          suffix=self.tld_name)
                zone = self.zone_client.create_zone(name=zone_name)[1]
                self.addCleanup(self.wait_zone_delete, self.zone_client,
                                zone['id'])
                waiters.wait_for_zone_status(self.zone_client, zone['id'],
                                             const.ACTIVE)

                # Create a recordset and wait till it's ACTIVE
                recordset_data = dns_data_utils.rand_recordset_data(
                    record_type='A', zone_name=zone['name'])
                resp, body = self.client.create_recordset(
                    zone['id'], recordset_data)

                self.addCleanup(self.wait_recordset_delete, self.client,
                                self.zone['id'], body['id'])
                self.assertEqual(const.PENDING, body['status'],
                                 'Failed, expected status is PENDING')

                LOG.info('Wait until the recordset is active')
                waiters.wait_for_recordset_status(self.client, zone['id'],
                                                  body['id'], const.ACTIVE)

                # Add "project_id" into the recordset_data
                recordset_data['project_id'] = zone['project_id']
                recordsets_created['primary'] = recordset_data

            if client == 'alt':
                # Create a zone and wait till it's ACTIVE
                zone_name = dns_data_utils.rand_zone_name(name="alt",
                                                          suffix=self.tld_name)
                alt_zone = self.alt_zone_client.create_zone(name=zone_name)[1]
                self.addCleanup(self.wait_zone_delete, self.alt_zone_client,
                                alt_zone['id'])
                waiters.wait_for_zone_status(self.alt_zone_client,
                                             alt_zone['id'], const.ACTIVE)

                # Create a recordset and wait till it's ACTIVE
                recordset_data = dns_data_utils.rand_recordset_data(
                    record_type='A', zone_name=alt_zone['name'])
                resp, body = self.alt_client.create_recordset(
                    alt_zone['id'], recordset_data)

                self.addCleanup(self.wait_recordset_delete, self.client,
                                self.zone['id'], body['id'])
                self.assertEqual(const.PENDING, body['status'],
                                 'Failed, expected status is PENDING')

                LOG.info('Wait until the recordset is active')
                waiters.wait_for_recordset_status(self.alt_client,
                                                  alt_zone['id'], body['id'],
                                                  const.ACTIVE)

                # Add "project_id" into the recordset_data
                recordset_data['project_id'] = alt_zone['project_id']
                recordsets_created['alt'] = recordset_data

        LOG.info('Created resordsets are {}:'.format(recordsets_created))
        return recordsets_created
    def test_create_SPF_with(self, data):
        post_model = data_utils.rand_spf_recordset(self.zone['name'], data)
        recordset = self.create_recordset(post_model)

        waiters.wait_for_recordset_status(
            self.recordset_client, self.zone['id'], recordset['id'], 'ACTIVE')