Пример #1
0
    def test_domain(self, domain_name, changed_domain_name):
        mydomain = domain.Domain(domain_name)
        self.assertTrue(mydomain.domain.islower())

        # test all properties
        # domain
        self.assertEqual(mydomain.domain, domain_name.lower())
        self.assertEqual(mydomain.protocol, 'http')
        self.assertEqual(mydomain.certificate, None)
        mydomain.domain = changed_domain_name
        self.assertEqual(mydomain.domain, changed_domain_name.lower())
        try:
            mydomain.certificate = 'SAN'
        except ValueError:
            self.assertTrue(True)

        my_other_domain = domain.Domain.init_from_dict({"domain": domain_name})
        self.assertEqual(my_other_domain.domain, domain_name.lower())

        try:
            domain.Domain(domain_name, 'https')
        except ValueError:
            self.assertTrue(True)

        my_https_domain = domain.Domain(domain_name, 'https', 'san')
        self.assertEqual(my_https_domain.protocol, 'https')
        self.assertEqual(my_https_domain.certificate, 'san')

        try:
            my_https_domain.certificate = 'non-sense'
        except ValueError:
            self.assertTrue(True)
Пример #2
0
    def test_create_service(self):
        service_name = 'NewService'
        myorigins = []
        mydomains = []

        myorigins.append(origin.Origin('mysite.com'))
        myorigins.append(origin.Origin('yoursite.io', port=80, ssl=True))

        mydomains.append(domain.Domain('oursite.org'))
        mydomains.append(domain.Domain('wiki.cc'))

        myservice = service.Service(service_name, mydomains, myorigins)

        # test all properties
        # name
        self.assertEqual(myservice.name, service_name)
        self.assertRaises(AttributeError, setattr, myservice, 'name',
                          service_name)

        # domains
        self.assertEqual(myservice.domains, mydomains)
        self.assertRaises(AttributeError, setattr, myservice, 'domains', [])

        # origins
        self.assertEqual(myservice.origins, myorigins)
        self.assertRaises(AttributeError, setattr, myservice, 'origins', [])
Пример #3
0
    def setUp(self):
        super(TestServiceModel, self).setUp()

        self.project_id = str(uuid.uuid4())
        self.service_id = str(uuid.uuid4())
        self.service_name = uuid.uuid1()
        self.flavor_id = "strawberry"

        self.myorigins = []
        self.mydomains = []
        self.myrestrictions = []
        self.mycaching = []
        self.log_delivery = {"enabled": False}

        self.myorigins.append(origin.Origin('mysite.com'))
        self.myorigins.append(origin.Origin('yoursite.io', port=80, ssl=True))

        self.mydomains.append(domain.Domain('oursite.org'))
        self.mydomains.append(domain.Domain('wiki.cc', 'https', 'shared'))

        # test a rule with referrer restriction
        r1 = restriction.Restriction('referrer_site', 'whitelist')
        self.r1_rules = [rule.Rule('referrer_restriction_rule_1')]
        self.r1_rules[0].http_host = 'www.some_bad_site.com'
        r1.rules = self.r1_rules
        self.myrestrictions.append(r1)
        self.myrestrictions.append(
            restriction.Restriction('client_ip', 'whitelist'))

        self.mycaching.append(cachingrule.CachingRule('images', 3600))
        self.mycaching.append(cachingrule.CachingRule('js', 7200))
Пример #4
0
    def test_update_remove_domains_provider_error(self):
        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')

        responders = [{
            'Fastly': {
                'id': str(uuid.uuid4()),
                'error': 'Create service failed'
            }
        }]

        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:
                access_urls_map[provider_name][access_urls['domain']] = (
                    access_urls['operator_url'])

        for responder in responders:
            for provider_name in responder:
                for domain_old in self.domains_old:
                    self.assertIsNotNone(
                        access_urls_map[provider_name][domain_old.domain])
Пример #5
0
    def test_update_add_domains(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')

        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',
                    'certificate':
                    'san',
                    'old_operator_url':
                    'old.operator.url.cdn99.mycdn.com'
                }]
            }
        }]

        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:
                access_urls_map[provider_name][access_urls['domain']] = (
                    access_urls['operator_url'])

        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])
Пример #6
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])
Пример #7
0
    def setUp(self):
        super(TestServicesUpdate, self).setUp()

        pyrax_cloud_dns_patcher = mock.patch('pyrax.cloud_dns')
        pyrax_cloud_dns_patcher.start()
        self.addCleanup(pyrax_cloud_dns_patcher.stop)

        pyrax_set_credentials_patcher = mock.patch('pyrax.set_credentials')
        pyrax_set_credentials_patcher.start()
        self.addCleanup(pyrax_set_credentials_patcher.stop)

        pyrax_set_setting_patcher = mock.patch('pyrax.set_setting')
        pyrax_set_setting_patcher.start()
        self.addCleanup(pyrax_set_setting_patcher.stop)

        rs_options_patcher = mock.patch.object(
            driver,
            'RACKSPACE_OPTIONS',
            new=RACKSPACE_OPTIONS
        )
        rs_options_patcher.start()
        self.addCleanup(rs_options_patcher.stop)

        self.client = mock.Mock()
        provider = driver.DNSProvider(self.conf)
        self.controller = provider.services_controller
        self.controller.client = self.client

        self.domains_old = [domain.Domain('test.domain.com'),
                            domain.Domain('blog.domain.com')]
        self.origins_old = []

        fastly_access_urls_old = [
            {
                u'provider_url': u'test.domain.com.global.prod.fastly.net',
                u'domain': u'test.domain.com',
                u'operator_url': u'test.domain.com.cdn80.mycdn.com'
            },
            {
                u'provider_url': u'blog.domain.com.global.prod.fastly.net',
                u'domain': u'blog.domain.com',
                u'operator_url': u'blog.domain.com.cdn80.mycdn.com'
            }]

        fastly_provider_details_old = mock.Mock()
        fastly_provider_details_old.access_urls = fastly_access_urls_old

        provider_details_old = {
            'Fastly': fastly_provider_details_old
        }

        self.service_old = service.Service(service_id=uuid.uuid4(),
                                           name='myservice',
                                           domains=self.domains_old,
                                           origins=self.origins_old,
                                           flavor_id='standard')
        self.service_old.provider_details = provider_details_old
Пример #8
0
    def test_update_flow_dns_exception(self):
        service_id = str(uuid.uuid4())
        domains_old = domain.Domain(domain='cdn.poppy.org')
        domains_new = domain.Domain(domain='mycdn.poppy.org')
        current_origin = origin.Origin(origin='poppy.org')
        service_old = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_old],
                                      origins=[current_origin],
                                      flavor_id='cdn')
        service_new = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_new],
                                      origins=[current_origin],
                                      flavor_id='cdn')

        kwargs = {
            'project_id':
            json.dumps(str(uuid.uuid4())),
            'auth_token':
            json.dumps(str(uuid.uuid4())),
            'service_id':
            json.dumps(service_id),
            'time_seconds':
            [i * self.time_factor for i in range(self.total_retries)],
            'service_old':
            json.dumps(service_old.to_dict()),
            'service_obj':
            json.dumps(service_new.to_dict()),
            'context_dict':
            context_utils.RequestContext().to_dict()
        }

        (service_controller, storage_controller, dns_controller,
         ssl_cert_controller) = self.all_controllers()

        with MonkeyPatchControllers(service_controller, dns_controller,
                                    storage_controller, ssl_cert_controller,
                                    memoized_controllers.task_controllers):

            self.patch_update_flow(service_controller, storage_controller,
                                   dns_controller)
            dns_controller.update = mock.Mock()
            dns_controller.update._mock_return_value = {
                'cdn_provider': {
                    'error':
                    'Whoops!',
                    'error_class':
                    'tests.unit.distributed_task'
                    '.taskflow.test_flows.DNSException'
                }
            }

            engines.run(update_service.update_service(), store=kwargs)
Пример #9
0
    def test_update_remove_domains_with_subdomain_not_found_exception(self):
        subdomain = mock.Mock()
        subdomain.add_records = mock.Mock()
        client = mock.Mock()
        client.find = mock.Mock(
            side_effect=exc.NotFound('Subdomain not found'))
        records = [mock.Mock(), mock.Mock()]
        client.search_records = mock.Mock(return_value=records)
        self.controller.client = client

        domains_new = [
            domain.Domain('test.domain.com'),
            domain.Domain('blog.domain.com')
        ]
        service_updates = service.Service(
            service_id=self.service_old.service_id,
            name='myservice',
            domains=domains_new,
            origins=[],
            flavor_id='standard')

        responders = [{
            'Fastly': {
                'id':
                str(uuid.uuid4()),
                'links': [{
                    'domain': u'blog.domain.com',
                    'href': u'blog.domain.com.global.prod.fastly.net',
                    'rel': 'access_url'
                }, {
                    'domain': u'test.domain.com',
                    'href': u'test.domain.com.global.prod.fastly.net',
                    'rel': 'access_url'
                }]
            }
        }]

        dns_details = self.controller.update(self.service_old, service_updates,
                                             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'])

        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])
Пример #10
0
    def test_update_add_domains_with_dns_exception(self):
        subdomain = mock.Mock()
        subdomain.add_records = mock.Mock()
        client = mock.Mock()
        client.find = mock.Mock(
            side_effect=Exception('DNS Exception'))
        self.controller.client = client

        domains_new = [domain.Domain('test.domain.com'),
                       domain.Domain('blog.domain.com'),
                       domain.Domain('pictures.domain.com')]
        service_updates = service.Service(
            service_id=self.service_old.service_id,
            name='myservice',
            domains=domains_new,
            origins=[],
            flavor_id='standard')

        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_updates,
                                             responders)
        for responder in responders:
            for provider_name in responder:
                    self.assertIsNotNone(dns_details[provider_name]['error'])
                    self.assertIsNotNone(
                        dns_details[provider_name]['error_detail'])
                    self.assertIsNotNone(
                        dns_details[provider_name]['error_class']
                    )
Пример #11
0
    def test_update_flow_dns_exception_with_retry_and_succeed(
            self, mock_creds):
        service_id = str(uuid.uuid4())
        domains_old = domain.Domain(domain='cdn.poppy.org')
        domains_new = domain.Domain(domain='mycdn.poppy.org')
        current_origin = origin.Origin(origin='poppy.org')
        service_old = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_old],
                                      origins=[current_origin],
                                      flavor_id='cdn')
        service_new = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_new],
                                      origins=[current_origin],
                                      flavor_id='cdn')

        kwargs = {
            'project_id':
            json.dumps(str(uuid.uuid4())),
            'auth_token':
            json.dumps(str(uuid.uuid4())),
            'service_id':
            json.dumps(service_id),
            'time_seconds':
            [i * self.time_factor for i in range(self.total_retries)],
            'service_old':
            json.dumps(service_old.to_dict()),
            'service_obj':
            json.dumps(service_new.to_dict()),
            'context_dict':
            context_utils.RequestContext().to_dict()
        }

        service_controller, storage_controller, dns_controller = \
            self.all_controllers()

        with MonkeyPatchControllers(service_controller, dns_controller,
                                    storage_controller,
                                    memoized_controllers.task_controllers):

            self.patch_update_flow(service_controller, storage_controller,
                                   dns_controller)
            dns_controller.update = mock.Mock()
            dns_responder_returns = self.dns_exceptions_and_succeed()

            dns_controller.update._mock_side_effect = (
                dns_responder for dns_responder in dns_responder_returns)

            engines.run(update_service.update_service(), store=kwargs)
Пример #12
0
    def test_delete_with_exception(self):
        provider_service_id = uuid.uuid1()

        # instantiate
        controller = services.ServiceController(self.driver)

        # mock.patch return values
        service = self.mock_service()
        service.id = uuid.uuid1()
        controller.client.get_service_by_name.return_value = service

        # test exception
        controller.client.delete_service.side_effect = None
        service_id = str(uuid.uuid4())
        current_domain = str(uuid.uuid1())
        domains_old = domain.Domain(domain=current_domain)
        current_origin = origin.Origin(origin='poppy.org')
        service_obj = Service(service_id=service_id,
                              name='poppy cdn service',
                              domains=[domains_old],
                              origins=[current_origin],
                              flavor_id='cdn',
                              project_id=str(uuid.uuid4()))

        exception = fastly.FastlyError(Exception('ding'))
        controller.client.delete_service.side_effect = exception
        resp = controller.delete(service_obj, provider_service_id)

        self.assertIn('error', resp[self.driver.provider_name])
Пример #13
0
    def test_delete_with_exception(self, mock_controllerclient, mock_driver):
        # test create with exceptions
        driver = mock_driver()
        driver.attach_mock(mock_controllerclient, 'client')
        driver.client.configure_mock(
            **{'get.return_value': fake_maxcdn_client_get_return_value})

        service_name = 'test_service_name'

        controller_with_delete_exception = services.ServiceController(driver)
        controller_with_delete_exception.client.configure_mock(
            **{
                'delete.side_effect':
                RuntimeError('Deleting service mysteriously failed.')
            })
        service_name = 'test_service_name'
        service_id = str(uuid.uuid4())
        current_domain = str(uuid.uuid1())
        domains_old = domain.Domain(domain=current_domain)
        current_origin = origin.Origin(origin='poppy.org')
        service_obj = Service(service_id=service_id,
                              name='poppy cdn service',
                              domains=[domains_old],
                              origins=[current_origin],
                              flavor_id='cdn',
                              project_id=str(uuid.uuid4()))
        resp = controller_with_delete_exception.delete(service_obj,
                                                       service_name)
        self.assertEqual(resp[driver.provider_name]['error'],
                         'Deleting service mysteriously failed.')
Пример #14
0
    def setUp(self):
        super(TestServices, self).setUp()

        driver_patcher = mock.patch('poppy.provider.akamai.driver.CDNProvider')
        mock_driver = driver_patcher.start()
        self.addCleanup(driver_patcher.stop)

        self.driver = mock_driver()
        self.policy_client = self.driver.policy_api_client
        self.ccu_client = self.driver.ccu_api_client

        self.driver.provider_name = 'Akamai'
        self.driver.http_conf_number = 1
        self.driver.akamai_https_access_url_suffix = str(uuid.uuid1())
        self.san_cert_cnames = [str(x) for x in range(7)]
        self.driver.san_cert_cnames = self.san_cert_cnames
        self.driver.regions = geo_zone_code_mapping.REGIONS
        self.driver.metrics_resolution = 86400
        self.controller = services.ServiceController(self.driver)
        service_id = str(uuid.uuid4())
        domains_old = domain.Domain(domain='cdn.poppy.org')
        current_origin = origin.Origin(origin='poppy.org')
        self.service_obj = Service(service_id=service_id,
                                   name='poppy cdn service',
                                   domains=[domains_old],
                                   origins=[current_origin],
                                   flavor_id='cdn')
Пример #15
0
    def create_ssl_certificate(self, project_id, cert_obj):

        if (not validators.is_valid_domain_name(cert_obj.domain_name)) or \
                (validators.is_root_domain(
                    domain.Domain(cert_obj.domain_name).to_dict())):
            # here created a http domain object but it does not matter http or
            # https
            raise ValueError('%s must be a valid non-root domain' %
                             cert_obj.domain_name)

        try:
            flavor = self.flavor_controller.get(cert_obj.flavor_id)
        # raise a lookup error if the flavor is not found
        except LookupError as e:
            raise e

        try:
            self.storage.create_certificate(project_id, cert_obj)
        # ValueError will be raised if the cert_info has already existed
        except ValueError as e:
            raise e

        providers = [p.provider_id for p in flavor.providers]
        kwargs = {
            'providers_list_json': json.dumps(providers),
            'project_id': project_id,
            'cert_obj_json': json.dumps(cert_obj.to_dict()),
            'context_dict': context_utils.get_current().to_dict()
        }
        self.distributed_task_controller.submit_task(
            create_ssl_certificate.create_ssl_certificate, **kwargs)
        return kwargs
Пример #16
0
    def test_delete_with_service_id_json_load_error(self):
        # This should trigger a json.loads error
        service_id = str(uuid.uuid4())
        current_domain = str(uuid.uuid1())
        domains_old = domain.Domain(domain=current_domain)
        current_origin = origin.Origin(origin='poppy.org')
        service_obj = Service(service_id=service_id,
                              name='poppy cdn service',
                              domains=[domains_old],
                              origins=[current_origin],
                              flavor_id='cdn',
                              project_id=str(uuid.uuid4()))

        provider_service_id = None
        controller = services.ServiceController(self.driver)

        controller.subcustomer_api_client.get.return_value = \
            mock.Mock(status_code=200,
                      ok=True,
                      content=json.dumps({"geo": "US"}))

        controller.subcustomer_api_client.delete.return_value = \
            mock.Mock(status_code=200,
                      ok=True)

        controller.policy_api_client.get.return_value = mock.Mock(
            status_code=200, text='Get successful')
        controller.policy_api_client.put.return_value = mock.Mock(
            status_code=200, text='Put successful')
        controller.policy_api_client.delete.return_value = mock.Mock(
            status_code=200, text='Delete successful')

        resp = controller.delete(service_obj, provider_service_id)
        self.assertIn('error', resp[self.driver.provider_name])
Пример #17
0
    def test_delete_flow_normal(self, mock_creds, mock_dns_client):
        service_id = str(uuid.uuid4())
        domains_old = domain.Domain(domain='cdn.poppy.org')
        current_origin = origin.Origin(origin='poppy.org')
        service_obj = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_old],
                                      origins=[current_origin],
                                      flavor_id='cdn')

        kwargs = {
            'project_id':
            json.dumps(str(uuid.uuid4())),
            'service_id':
            json.dumps(service_id),
            'time_seconds':
            [i * self.time_factor for i in range(self.total_retries)],
            'provider_details':
            json.dumps(
                dict([(k, v.to_dict())
                      for k, v in service_obj.provider_details.items()]))
        }

        service_controller, storage_controller, dns_controller = \
            self.all_controllers()

        with MonkeyPatchControllers(service_controller, dns_controller,
                                    storage_controller,
                                    memoized_controllers.task_controllers):

            self.patch_delete_flow(service_controller, storage_controller,
                                   dns_controller)
            engines.run(delete_service.delete_service(), store=kwargs)
Пример #18
0
    def test_services_action_with_domain_existing_domain(self):
        project_id = str(uuid.uuid4())
        service_id = str(uuid.uuid4())
        domains = domain.Domain(domain='happy.strawberries.com')
        current_origin = origin.Origin(origin='poppy.org')
        mock_service = service.Service(service_id=service_id,
                                       name='poppy cdn service',
                                       domains=[domains],
                                       origins=[current_origin],
                                       flavor_id='cdn',
                                       project_id=project_id)

        DefaultServicesController.get_service_by_domain_name = mock.Mock(
            return_value=mock_service)
        response = self.app.post('/v1.0/admin/services/action',
                                 params=json.dumps({
                                     'action':
                                     'enable',
                                     'domain':
                                     'happy.strawberries.com'
                                 }),
                                 headers={
                                     'Content-Type': 'application/json',
                                     'X-Project-ID': project_id
                                 },
                                 expect_errors=True)

        self.assertEqual(response.status_code, 202)
Пример #19
0
 def format_result(result):
     service_id = result.get('service_id')
     name = str(result.get('service_name'))
     origins = [o for o in result.get('origins', [])]
     domains = [d for d in result.get('domains', [])]
     origins = [origin.Origin(o['origin'],
                              hostheadertype='domain',
                              hostheadervalue='blog.mywebsite.com',
                              port=o.get('port', 80),
                              ssl=o.get('ssl', False))
                for o in origins]
     domains = [domain.Domain(d['domain'], d['protocol'], d['certificate'])
                for d in domains]
     flavor_id = result.get('flavor_id')
     s = service.Service(service_id, name, domains, origins, flavor_id)
     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')
         provider_detail_obj = provider_details.ProviderDetail(
             provider_service_id=provider_service_id,
             access_urls=access_urls,
             status=status)
         provider_details_dict[provider_name] = provider_detail_obj
     s.provider_details = provider_details_dict
     return s
Пример #20
0
    def test_update_add_domains_https_upgrade_regex_exception(self, re_mock):
        re_mock.return_value.groups.return_value = (None, )
        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')
        ]

        self.service_old.domains = domains_new
        service_new = service.Service(service_id=self.service_old.service_id,
                                      name='myservice',
                                      domains=domains_new,
                                      origins=[],
                                      flavor_id='standard')

        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',
                    'certificate':
                    'san',
                    'old_operator_url':
                    'old.operator.url.cdn99.mycdn.com'
                }]
            }
        }]

        dns_details = self.controller.update(self.service_old, service_new,
                                             responders)
        self.assertTrue('error' in dns_details['Fastly'])
        self.assertTrue('error_detail' in dns_details['Fastly'])
        self.assertTrue('error_class' in dns_details['Fastly'])
        self.assertTrue('ValueError' in dns_details['Fastly']['error_class'])
Пример #21
0
    def test_post_job_positive(self, job_tuple):
        job_type, cert_type = job_tuple
        # mock ssl storage returning a cert
        self.mock_storage.certificates_controller.\
            get_certs_by_domain.return_value = [
                mock.Mock()
            ]
        # mock service storage returning a service with domain with
        # correct protocol + cert
        self.mock_storage.services_controller. \
            get_service_details_by_domain_name.return_value = service.Service(
                'service_id',
                'name',
                [
                    domain.Domain(
                        "www.example.com",
                        protocol='https',
                        certificate=cert_type
                    )
                ],
                [],
                'flavor_id',
                project_id='project_id'
            )

        san_mapping_queue = self.manager_driver.providers[
            'akamai'].obj.san_mapping_queue
        cert_key = ('san cert' if cert_type == 'san' else 'sni_cert')
        san_mapping_queue.traverse_queue.return_value = [
            json.dumps({
                "domain_name":
                "www.example.com",
                "flavor_id":
                "flavor_id",
                "project_id":
                "project_id",
                "cert_type":
                cert_type,
                "cert_details": {
                    "Akamai": {
                        "extra_info": {
                            cert_key: "{0}.example.com".format(cert_type),
                            "akamai_spsId": 1
                        }
                    }
                },
                'property_activated':
                (True if job_type == "akamai_check_and_update_cert_status" else
                 False)
            })
        ]

        run_list, ignore_list = self.bgc.post_job(job_type,
                                                  {'project_id': 'project_id'})
        self.assertEqual(1, len(run_list))
        self.assertEqual(0, len(ignore_list))

        self.assertTrue(
            self.bgc.distributed_task_controller.submit_task.called)
Пример #22
0
    def test_service_state_flow_dns_exception(self, mock_creds):
        service_id = str(uuid.uuid4())
        domains_old = domain.Domain(domain='cdn.poppy.org')
        current_origin = origin.Origin(origin='poppy.org')
        service_obj = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_old],
                                      origins=[current_origin],
                                      flavor_id='cdn')

        enable_kwargs = {
            'project_id':
            json.dumps(str(uuid.uuid4())),
            'state':
            'enable',
            'service_obj':
            json.dumps(service_obj.to_dict()),
            'time_seconds':
            [i * self.time_factor for i in range(self.total_retries)],
            'context_dict':
            context_utils.RequestContext().to_dict()
        }

        disable_kwargs = enable_kwargs.copy()
        disable_kwargs['state'] = 'disable'

        service_controller, storage_controller, dns_controller = \
            self.all_controllers()

        with MonkeyPatchControllers(service_controller, dns_controller,
                                    storage_controller,
                                    memoized_controllers.task_controllers):

            self.patch_service_state_flow(service_controller,
                                          storage_controller, dns_controller)
            dns_controller.enable = mock.Mock()
            dns_controller.enable._mock_return_value = {
                'cdn_provider': {
                    'error':
                    'Whoops!',
                    'error_class':
                    'tests.unit.distributed_task'
                    '.taskflow.test_flows.DNSException'
                }
            }
            dns_controller.disable = mock.Mock()
            dns_controller.disable._mock_return_value = {
                'cdn_provider': {
                    'error':
                    'Whoops!',
                    'error_class':
                    'tests.unit.distributed_task'
                    '.taskflow.test_flows.DNSException'
                }
            }
            engines.run(update_service_state.enable_service(),
                        store=enable_kwargs)
            engines.run(update_service_state.disable_service(),
                        store=disable_kwargs)
Пример #23
0
    def test_get_provider_access_url_http(self):

        _domain = domain.Domain('densely.sage.com', 'http', certificate=None)
        dp = 'test.abc.com'
        edge_host_name = None
        http_url = self.controller._get_provider_access_url(
            _domain, dp, edge_host_name)
        expected_out = 'abc.com.test.edgesuite.net'
        self.assertEqual(http_url, expected_out)
Пример #24
0
    def test_domain(self):

        domain_name = 'www.mydomain.com'
        mydomain = domain.Domain(domain_name)

        # test all properties
        # domain
        self.assertEqual(mydomain.domain, domain_name)
        self.assertRaises(AttributeError, setattr, mydomain, 'domain',
                          domain_name)
Пример #25
0
 def get_service_details_by_domain_name(self, domain_name,
                                        project_id=None):
     r = service.Service(
         str(uuid.uuid4()),
         str(uuid.uuid4()),
         [domain.Domain('wiki.cc', 'https', 'shared')],
         [origin.Origin('mysite.com')],
         "strawberry")
     r.provider_details = MockProviderDetails(r.service_id)
     return r
Пример #26
0
    def test_update_flow_normal(self):
        service_id = str(uuid.uuid4())
        domains_old = domain.Domain(domain='cdn.poppy.org')
        domains_new = domain.Domain(domain='mycdn.poppy.org')
        current_origin = origin.Origin(origin='poppy.org')
        service_old = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_old],
                                      origins=[current_origin],
                                      flavor_id='cdn')
        service_new = service.Service(service_id=service_id,
                                      name='poppy cdn service',
                                      domains=[domains_new],
                                      origins=[current_origin],
                                      flavor_id='cdn')

        kwargs = {
            'project_id':
            json.dumps(str(uuid.uuid4())),
            'auth_token':
            json.dumps(str(uuid.uuid4())),
            'service_id':
            json.dumps(service_id),
            'time_seconds':
            [i * self.time_factor for i in range(self.total_retries)],
            'service_old':
            json.dumps(service_old.to_dict()),
            'service_obj':
            json.dumps(service_new.to_dict()),
            'context_dict':
            context_utils.RequestContext().to_dict()
        }

        (service_controller, storage_controller, dns_controller,
         ssl_cert_controller) = self.all_controllers()

        with MonkeyPatchControllers(service_controller, dns_controller,
                                    storage_controller, ssl_cert_controller,
                                    memoized_controllers.task_controllers):

            self.patch_update_flow(service_controller, storage_controller,
                                   dns_controller)
            engines.run(update_service.update_service(), store=kwargs)
Пример #27
0
 def test_get_provider_access_url_san_sni(self):
     certificates = ["san", "sni"]
     for certificate in certificates:
         _domain = domain.Domain('densely.sage.com',
                                 'https',
                                 certificate=certificate)
         dp = 'test.abc.com'
         edge_host_name = "test.com"
         https_url = self.controller._get_provider_access_url(
             _domain, dp, edge_host_name)
         expected_out = 'test.com.' + self.driver.akamai_https_access_url_suffix
         self.assertEqual(https_url, expected_out)
Пример #28
0
    def setUp(self, mock_set_credentials):
        super(TestServicesUpdate, self).setUp()
        self.client = mock.Mock()
        provider = driver.DNSProvider(self.conf)
        self.controller = provider.services_controller
        self.controller.client = self.client

        self.domains_old = [
            domain.Domain('test.domain.com'),
            domain.Domain('blog.domain.com')
        ]
        self.origins_old = []

        fastly_access_urls_old = [{
            u'provider_url':
            u'test.domain.com.global.prod.fastly.net',
            u'domain':
            u'test.domain.com',
            u'operator_url':
            u'test.domain.com.cdn80.mycdn.com'
        }, {
            u'provider_url':
            u'blog.domain.com.global.prod.fastly.net',
            u'domain':
            u'blog.domain.com',
            u'operator_url':
            u'blog.domain.com.cdn80.mycdn.com'
        }]

        fastly_provider_details_old = mock.Mock()
        fastly_provider_details_old.access_urls = fastly_access_urls_old

        provider_details_old = {'Fastly': fastly_provider_details_old}

        self.service_old = service.Service(service_id=uuid.uuid4(),
                                           name='myservice',
                                           domains=self.domains_old,
                                           origins=self.origins_old,
                                           flavor_id='standard')
        self.service_old.provider_details = provider_details_old
Пример #29
0
    def test_post_job_domain_type_modified_on_service(self, cert_type):
        self.mock_storage.certificates_controller.\
            get_certs_by_domain.return_value = [
                mock.Mock()
            ]
        # simulate domain being changed from https+san to http
        self.mock_storage.services_controller. \
            get_service_details_by_domain_name.return_value = service.Service(
                'service_id',
                'name',
                [
                    domain.Domain(
                        "www.example.com",
                        protocol='http',
                    )
                ],
                [],
                'flavor_id',
                project_id='project_id'
            )
        cert_key = ('san cert' if cert_type == 'san' else 'sni_cert')
        san_mapping_queue = self.manager_driver.providers[
            'akamai'].obj.san_mapping_queue
        san_mapping_queue.traverse_queue.return_value = [
            json.dumps({
                "domain_name": "www.example.com",
                "flavor_id": "flavor_id",
                "project_id": "project_id",
                "cert_type": cert_type,
                "cert_details": {
                    "Akamai": {
                        "extra_info": {
                            cert_key: "san.example.com",
                            "akamai_spsId": 1
                        }
                    }
                },
                'property_activated': True
            })
        ]

        run_list, ignore_list = self.bgc.post_job(
            "akamai_update_papi_property_for_mod_{0}".format(cert_type),
            {'project_id': 'project_id'}
        )
        self.assertEqual(0, len(run_list))
        self.assertEqual(1, len(ignore_list))

        self.assertEqual(
            False,
            self.bgc.distributed_task_controller.submit_task.called
        )
Пример #30
0
 def test_delete(self):
     service_id = str(uuid.uuid4())
     current_domain = str(uuid.uuid1())
     domains_old = domain.Domain(domain=current_domain)
     current_origin = origin.Origin(origin='poppy.org')
     service_obj = Service(service_id=service_id,
                           name='poppy cdn service',
                           domains=[domains_old],
                           origins=[current_origin],
                           flavor_id='cdn',
                           project_id=str(uuid.uuid4()))
     response = self.sc.delete(service_obj, self.test_provider_service_id)
     self.assertTrue(response is not None)