Ejemplo n.º 1
0
    def update_zone(self,
                    uuid,
                    email=None,
                    ttl=None,
                    description=None,
                    wait_until=False,
                    params=None):
        """Update a zone with the specified parameters.
        :param uuid: The unique identifier of the zone.
        :param email: The email for the zone.
            Default: Random Value
        :param ttl: The ttl for the zone.
            Default: Random Value
        :param description: A description of the zone.
            Default: Random Value
        :param wait_until: Block until the zone reaches the desiered status
        :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 updated zone.
        """
        zone = {
            'email': email or dns_data_utils.rand_email(),
            'ttl': ttl or dns_data_utils.rand_ttl(),
            'description': description or data_utils.rand_name('test-zone'),
        }

        resp, body = self._update_request('zones', uuid, zone, params=params)

        # Update Zone should Return a HTTP 202
        self.expected_success(202, resp.status)

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

        return resp, body
    def update_zone(self, uuid, email=None, ttl=None,
                    description=None, wait_until=False, params=None):
        """Update a zone with the specified parameters.
        :param uuid: The unique identifier of the zone.
        :param email: The email for the zone.
            Default: Random Value
        :param ttl: The ttl for the zone.
            Default: Random Value
        :param description: A description of the zone.
            Default: Random Value
        :param wait_until: Block until the zone reaches the desiered status
        :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 updated zone.
        """
        zone = {
            'email': email or dns_data_utils.rand_email(),
            'ttl': ttl or dns_data_utils.rand_ttl(),
            'description': description or data_utils.rand_name('test-zone'),
        }

        resp, body = self._update_request('zones', uuid, zone, params=params)

        # Update Zone should Return a HTTP 202
        self.expected_success(202, resp.status)

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

        return resp, body
    def test_update_recordset_one_field(self):
        recordset_data = data_utils.rand_recordset_data(
            record_type='A', zone_name=self.zone['name'])

        LOG.info('Create a recordset')
        _, record = self.client.create_recordset(self.zone['id'],
                                                 recordset_data)

        recordset_data = {'ttl': data_utils.rand_ttl(start=record['ttl'] + 1)}

        LOG.info('Update the recordset')
        _, update = self.client.update_recordset(self.zone['id'], record['id'],
                                                 recordset_data)

        self.assertEqual(record['name'], update['name'])
        self.assertEqual(record['records'], update['records'])
        self.assertEqual(record['description'], update['description'])
        self.assertNotEqual(record['ttl'], update['ttl'])
    def test_serial_changes_on_update(self):
        LOG.info('Create a zone')
        zone_name = dns_data_utils.rand_zone_name(
            name="serial_changes_on_update", suffix=self.tld_name)
        zone = self.client.create_zone(name=zone_name,
                                       wait_until=const.ACTIVE)[1]
        self.addCleanup(self.wait_zone_delete, self.client, zone['id'])

        LOG.info("Update Zone's email")
        update_email = self.client.update_zone(
            zone['id'], email=dns_data_utils.rand_email())[1]
        self.assertNotEqual(
            zone['serial'], update_email['serial'],
            "Failed, expected: 'Serial' is supposed to be changed "
            "on Email update.")

        LOG.info("Update Zone's TTL")
        update_ttl = self.client.update_zone(zone['id'],
                                             ttl=dns_data_utils.rand_ttl())[1]
        self.assertNotEqual(
            update_email['serial'], update_ttl['serial'],
            "Failed, expected: 'Serial' is supposed to be changed "
            "on TTL update.")

        LOG.info("Update Zone's email and description")
        update_email_description = self.client.update_zone(
            zone['id'],
            email=dns_data_utils.rand_email(),
            description=data_utils.rand_name())[1]
        self.assertNotEqual(
            update_ttl['serial'], update_email_description['serial'],
            "Failed, expect the Serial to change "
            "when the Email and Description are updated")

        LOG.info("Update Zone's description")
        update_description = self.client.update_zone(
            zone['id'], description=data_utils.rand_name())[1]
        self.assertEqual(
            update_email_description['serial'], update_description['serial'],
            "Failed, expect the Serial to not change "
            "when the Description is updated")
    def set_ptr_record(self, floatingip_id, ptr_name=None,
                       ttl=None, description=None, headers=None,
                       tld=None):
        """Set a PTR record for the given FloatingIP

        :param floatingip_id: valid UUID of floating IP to be used.
        :param ptr_name PTR record name or random if not provided.
        :param ttl TTL or random valid value if not provided.
        :param description Description or random if not provided.
        :param headers (dict): The headers to use for the request.
        :param tld, the TLD to be used in ptrdname generated value.
        :return: created PTR dictionary.
        """
        ptr = {
            'ptrdname': ptr_name or dns_data_utils.rand_domain_name(tld),
            'ttl': ttl or dns_data_utils.rand_ttl(),
            'description': description or data_utils.rand_name('test-ptr')}

        return self._update_request(
            resource='reverse/floatingips/{}'.format(CONF.identity.region),
            uuid=floatingip_id, data=ptr, headers=headers,
            uuid_prefix_char=':')[1]
    def create_zone(self,
                    name=None,
                    email=None,
                    ttl=None,
                    description=None,
                    attributes=None,
                    wait_until=False,
                    zone_type=const.PRIMARY_ZONE_TYPE,
                    primaries=None,
                    params=None,
                    project_id=None):
        """Create a zone with the specified parameters.

        :param name: The name of the zone.
            Default: Random Value
        :param email: The email for the zone.
            Default: Random Value
        :param ttl: The ttl for the zone.
            Default: Random Value
        :param description: A description of the zone.
            Default: Random Value
        :param attributes: Key:Value pairs of information about this zone,
               and the pool the user would like to place the zone in.
               This information can be used by the scheduler to place
               zones on the correct pool.
        :param wait_until: Block until the zone reaches the desiered status
        :param zone_type: PRIMARY or SECONDARY
            Default: PRIMARY
        :param primaries: List of Primary nameservers. Required for SECONDARY
            Default: None
        :param params: A Python dict that represents the query paramaters to
                       include in the request URI.
        :param project_id: When specified, overrides the project ID the zone
                           will be associated with.
        :return: A tuple with the server response and the created zone.
        """

        zone = {
            'name':
            name or dns_data_utils.rand_zone_name() if name != '' else '',
            'email':
            email or dns_data_utils.rand_email() if email != '' else '',
            'ttl':
            ttl or dns_data_utils.rand_ttl() if ttl != 0 else 0,
            'description':
            description or data_utils.rand_name('test-zone')
            if description != '' else '',
            'attributes':
            attributes or {
                'attribute_key': data_utils.rand_name('attribute_value')
            }
        }
        # If SECONDARY, "email" and "ttl" cannot be supplied
        if zone_type == const.SECONDARY_ZONE_TYPE:
            zone['type'] = zone_type
            del zone['email']
            del zone['ttl']
            if primaries is None:
                raise AttributeError(
                    'Error - "primaries" is mandatory parameter'
                    ' for a SECONDARY zone type')

            zone['masters'] = primaries

        headers = None
        extra_headers = False
        if project_id:
            headers = {'x-auth-sudo-project-id': project_id}
            extra_headers = True

        resp, body = self._create_request('zones',
                                          zone,
                                          params=params,
                                          headers=headers,
                                          extra_headers=extra_headers)

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

        if wait_until:
            waiters.wait_for_zone_status(self,
                                         body['id'],
                                         wait_until,
                                         headers=headers)

        return resp, body