Beispiel #1
0
    def test_update_add_domains_keeps_log_delivery(self):
        subdomain = mock.Mock()
        subdomain.add_records = mock.Mock()
        self.client.find = mock.Mock(return_value=subdomain)

        domains_new = [
            domain.Domain('test.domain.com'),
            domain.Domain('blog.domain.com'),
            domain.Domain('pictures.domain.com')
        ]

        service_new = service.Service(
            service_id=self.service_old.service_id,
            name='myservice',
            domains=domains_new,
            origins=[],
            flavor_id='standard',
            log_delivery=log_delivery.LogDelivery(enabled=True))
        self.service_old.log_delivery = log_delivery.LogDelivery(enabled=True)
        responders = [{
            'Fastly': {
                'id':
                str(uuid.uuid4()),
                'links': [{
                    'domain': u'test.domain.com',
                    'href': u'test.domain.com.global.prod.fastly.net',
                    'rel': 'access_url'
                }, {
                    'domain': u'blog.domain.com',
                    'href': u'blog.domain.com.global.prod.fastly.net',
                    'rel': 'access_url'
                }, {
                    'domain': u'pictures.domain.com',
                    'href': u'pictures.domain.com.global.prod.fastly.net',
                    'rel': 'access_url'
                }]
            }
        }]

        dns_details = self.controller.update(self.service_old, service_new,
                                             responders)
        access_urls_map = {}
        for provider_name in dns_details:
            access_urls_map[provider_name] = {}
            access_urls_list = dns_details[provider_name]['access_urls']
            for access_urls in access_urls_list:
                if 'operator_url' in access_urls:
                    access_urls_map[provider_name][access_urls['domain']] = (
                        access_urls['operator_url'])
                if 'log_delivery' in access_urls:
                    for ld_url in access_urls['log_delivery']:
                        self.assertIsNotNone(ld_url['internalURL'])
                        self.assertIsNotNone(ld_url['publicURL'])

        for responder in responders:
            for provider_name in responder:
                for domain_new in domains_new:
                    self.assertIsNotNone(
                        access_urls_map[provider_name][domain_new.domain])
Beispiel #2
0
 def __init__(self,
              service_id,
              name,
              domains,
              origins,
              flavor_id,
              caching=[],
              restrictions=[],
              log_delivery=None,
              operator_status='enabled',
              project_id=''):
     self._service_id = str(service_id)
     self._name = name
     self._domains = domains
     self._origins = origins
     self._flavor_id = flavor_id
     self._caching = caching
     self._restrictions = restrictions
     self._log_delivery = log_delivery or ld.LogDelivery(False)
     self._status = 'create_in_progress'
     self._provider_details = {}
     self._operator_status = operator_status
     self._project_id = project_id
Beispiel #3
0
def load_from_json(json_data):
    enabled = json_data.get("enabled", False)
    result = ld.LogDelivery(enabled)
    return result
Beispiel #4
0
    def format_result(result):
        """format_result.

        :param result
        :returns formatted result
        """
        service_id = result.get('service_id')
        project_id = result.get('project_id')
        name = result.get('service_name')

        flavor_id = result.get('flavor_id')
        origins = [json.loads(o) for o in result.get('origins', []) or []]
        domains = [json.loads(d) for d in result.get('domains', []) or []]
        restrictions = [
            json.loads(r) for r in result.get('restrictions', []) or []
        ]
        caching_rules = [
            json.loads(c) for c in result.get('caching_rules', []) or []
        ]
        log_delivery = json.loads(result.get('log_delivery', '{}') or '{}')
        operator_status = result.get('operator_status', 'enabled')

        # create models for each item
        origins = [
            origin.Origin(o['origin'], o.get('hostheadertype', 'domain'),
                          o.get('hostheadervalue', None), o.get('port', 80),
                          o.get('ssl', False), [
                              rule.Rule(rule_i.get('name'),
                                        request_url=rule_i.get('request_url'))
                              for rule_i in o.get('rules', [])
                          ]) for o in origins
        ]

        domains = [
            domain.Domain(d['domain'], d.get('protocol', 'http'),
                          d.get('certificate', None)) for d in domains
        ]

        restrictions = [
            restriction.Restriction(r.get('name'), r.get(
                'access', 'whitelist'), [
                    rule.Rule(r_rule.get('name'),
                              referrer=r_rule.get('referrer'),
                              client_ip=r_rule.get('client_ip'),
                              geography=r_rule.get('geography'),
                              request_url=r_rule.get('request_url', "/*")
                              or "/*") for r_rule in r['rules']
                ]) for r in restrictions
        ]

        caching_rules = [
            cachingrule.CachingRule(
                caching_rule.get('name'), caching_rule.get('ttl'), [
                    rule.Rule(rule_i.get('name'),
                              request_url=rule_i.get('request_url', '/*')
                              or '/*') for rule_i in caching_rule['rules']
                ]) for caching_rule in caching_rules
        ]

        log_delivery = ld.LogDelivery(log_delivery.get('enabled', False))

        # create the service object
        s = service.Service(service_id=service_id,
                            name=name,
                            domains=domains,
                            origins=origins,
                            flavor_id=flavor_id,
                            caching=caching_rules,
                            restrictions=restrictions,
                            log_delivery=log_delivery,
                            operator_status=operator_status,
                            project_id=project_id)

        # format the provider details
        provider_detail_results = result.get('provider_details') or {}
        provider_details_dict = {}
        for provider_name in provider_detail_results:
            provider_detail_dict = json.loads(
                provider_detail_results[provider_name])
            provider_service_id = provider_detail_dict.get('id', None)
            access_urls = provider_detail_dict.get('access_urls', [])
            status = provider_detail_dict.get('status', u'unknown')
            domains_certificate_status = (provider_detail_dict.get(
                'domains_certificate_status', {}))
            error_message = provider_detail_dict.get('error_message', None)

            provider_detail_obj = provider_details.ProviderDetail(
                provider_service_id=provider_service_id,
                access_urls=access_urls,
                domains_certificate_status=domains_certificate_status,
                status=status,
                error_message=error_message)
            provider_details_dict[provider_name] = provider_detail_obj
        s.provider_details = provider_details_dict

        # return the service
        return s