Example #1
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])
Example #2
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.')
Example #3
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')
Example #4
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])
Example #5
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)
Example #6
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()))
     resp = self.controller.delete(project_id=service_obj.project_id,
                                   service_name=self.service_name)
     self.assertIn('id', resp[self.driver.provider_name])
Example #7
0
 def setUp(self, mock_controller_policy_api_client,
           mock_controller_ccu_api_client, mock_driver):
     super(TestServices, self).setUp()
     self.driver = mock_driver()
     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.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')
Example #8
0
 def test_delete_exceptions(self):
     # delete_distribution: Exception
     self.controller.client.delete_distribution.side_effect = Exception(
         'Deleting service failed.')
     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 = self.controller.delete(project_id=service_obj.project_id,
                                   service_name=self.service_name)
     self.assertIn('error', resp[self.driver.provider_name])
Example #9
0
 def test_delete(self):
     new_driver = driver.CDNProvider(self.conf)
     # instantiate
     controller = services.ServiceController(new_driver)
     # test create, everything goes through successfully
     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.delete(service_obj, service_name)
     self.assertIn('id', resp[new_driver.provider_name])
Example #10
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()))

        provider_service_id = json.dumps([{'policy_name': current_domain,
                                           'protocol': 'http',
                                           'certificate': 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('id', resp[self.driver.provider_name])
Example #11
0
    def test_delete_with_exception(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()))
        provider_service_id = json.dumps([{'policy_name': str(uuid.uuid1()),
                                           'protocol': 'http',
                                           'certificate': None}])

        # test exception
        exception = RuntimeError('ding')
        self.controller.policy_api_client.delete.side_effect = exception
        resp = self.controller.delete(service_obj, provider_service_id)

        self.assertIn('error', resp[self.driver.provider_name])
Example #12
0
    def test_delete(self):
        provider_service_id = uuid.uuid1()

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

        # clear run
        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()))
        resp = controller.delete(service_obj, provider_service_id)
        controller.client.delete_service.assert_called_once_with(
            provider_service_id)
        self.assertIn('id', resp[self.driver.provider_name])
Example #13
0
    def test_delete_failed(self, mock_controllerclient, mock_driver):
        # test create with exceptions
        mock_response = mock.MagicMock()
        mock_response.text = 'Mock -- something went wrong!'
        mock_dict = {u'code': 500}
        mock_response.__getitem__.side_effect = mock_dict.__getitem__
        driver = mock_driver()
        driver.attach_mock(mock_controllerclient, 'client')
        driver.client.configure_mock(**{'delete.return_value': mock_response})

        controller = services.ServiceController(driver)
        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.delete(service_obj, service_name)
        self.assertIn('error', resp[driver.provider_name])