コード例 #1
0
ファイル: flavors.py プロジェクト: yunhaia/poppy
    def get(self, flavor_id):
        """get.

        :param flavor_id
        :returns flavor The specified Flavor
        """
        args = {
            'flavor_id': flavor_id
        }
        result = self.session.execute(CQL_GET, args)

        flavors = [
            flavor.Flavor(
                f['flavor_id'],
                [flavor.Provider(p_id, p_url)
                 for p_id, p_url in f['providers'].items()]
                if f['providers'] is not None else []
            )
            for f in result]

        if (len(flavors) == 1):
            return flavors[0]
        elif (len(flavors) > 1):
            raise LookupError(
                u"More than one flavor with the id '{0}' was retrieved."
                .format(flavor_id))
        else:
            raise LookupError(
                u"Could not find a flavor with the id '{0}'".format(flavor_id))
コード例 #2
0
ファイル: test_flavors.py プロジェクト: yunhaia/poppy
    def test_create_no_providers(self):
        self.flavor_id = uuid.uuid1()

        my_flavor = flavor.Flavor(self.flavor_id)

        # test all properties
        self.assertEqual(my_flavor.flavor_id, self.flavor_id)
        self.assertEqual(len(my_flavor.providers), 0)
コード例 #3
0
    def test_add_flavor_exist(self, value, mock_session, mock_execute):
        self.fc.get = mock.Mock(return_value=model_flavor.Flavor(
            flavor_id=value['id']))

        # mock the response from cassandra
        mock_execute.execute.return_value = value
        new_flavor = flavor.load_from_json(value)

        self.assertRaises(ValueError, self.fc.add, new_flavor)
コード例 #4
0
    def test_add(self):
        flavor_id = uuid.uuid1()
        providers = []

        providers.append(flavor.Provider("mock", uuid.uuid1()))
        providers.append(flavor.Provider("mock", uuid.uuid1()))
        providers.append(flavor.Provider("mock", uuid.uuid1()))

        new_flavor = flavor.Flavor(flavor_id, providers)

        self.fc.add(new_flavor)
        self.fc.storage.add.assert_called_once_with(new_flavor)
コード例 #5
0
ファイル: test_flavors.py プロジェクト: yunhaia/poppy
    def test_create_with_providers(self):
        self.flavor_id = uuid.uuid1()
        self.providers = []

        self.providers.append(flavor.Provider(uuid.uuid1(), uuid.uuid1()))
        self.providers.append(flavor.Provider(uuid.uuid1(), uuid.uuid1()))
        self.providers.append(flavor.Provider(uuid.uuid1(), uuid.uuid1()))

        my_flavor = flavor.Flavor(self.flavor_id, self.providers)

        # test all properties
        self.assertEqual(my_flavor.flavor_id, self.flavor_id)
        self.assertEqual(len(my_flavor.providers), len(self.providers))
コード例 #6
0
ファイル: flavor.py プロジェクト: yunhaia/poppy
def load_from_json(json_data):

    flavor_id = json_data['id']
    providers = []

    for p in json_data['providers']:
        provider_id = p['provider']
        provider_url = [
            item['href'] for item in p['links']
            if item['rel'] == 'provider_url'
        ][0]

        provider = flavor.Provider(provider_id, provider_url)
        providers.append(provider)

    new_flavor = flavor.Flavor(flavor_id, providers)

    return new_flavor
コード例 #7
0
ファイル: flavors.py プロジェクト: yunhaia/poppy
    def list(self):
        """list.

        :returns list List the supported flavors
        """

        # get all
        result = self.session.execute(CQL_GET_ALL)

        flavors = [
            flavor.Flavor(
                f['flavor_id'],
                [flavor.Provider(p_id, p_url)
                 for p_id, p_url in f['providers'].items()]
                if f['providers'] is not None else [])
            for f in result]

        return flavors
コード例 #8
0
ファイル: flavors.py プロジェクト: yunhaia/poppy
 def get(self, flavor_id):
     f = flavor.Flavor("standard",
                       [flavor.Provider("mock", "www.mock_provider.com")])
     if flavor_id == "non_exist":
         raise LookupError("More than one flavor/no record was retrieved.")
     return f
コード例 #9
0
ファイル: flavors.py プロジェクト: yunhaia/poppy
 def list(self):
     f = flavor.Flavor("standard",
                       [flavor.Provider("mock", "www.mock_provider.com")])
     return [f]
コード例 #10
0
    def test_create(self):
        # fake one return value
        self.sc.flavor_controller.get.return_value = flavor.Flavor(
            "standard", [
                flavor.Provider("cloudfront", "www.cloudfront.com"),
                flavor.Provider("fastly", "www.fastly.com"),
                flavor.Provider("mock", "www.mock_provider.com")
            ])

        providers = self.sc._driver.providers

        # mock responses from provider_wrapper.create call
        # to get code coverage
        def get_provider_extension_by_name(name):
            if name == "cloudfront":
                return_mock = mock.Mock(
                    return_value={
                        'Cloudfront': {
                            'id':
                            '08d2e326-377e-11e4-b531-3c15c2b8d2d6',
                            'links': [{
                                'href': 'www.mysite.com',
                                'rel': 'access_url'
                            }],
                            'status':
                            "deploy_in_progress"
                        }
                    })
                service_controller = mock.Mock(create=return_mock)
                return mock.Mock(
                    obj=mock.Mock(provider_name='CloudFront',
                                  service_controller=service_controller))
            elif name == "fastly":
                return_mock = mock.Mock(
                    return_value={
                        'Fastly': {
                            'error':
                            "fail to create service",
                            'error_detail':
                            'Fastly Create failed'
                            ' because of XYZ'
                        }
                    })

                service_controller = mock.Mock(create=return_mock)
                return mock.Mock(
                    obj=mock.Mock(provider_name=name.title(),
                                  service_controller=service_controller))
            else:
                return_mock = mock.Mock(
                    return_value={
                        name.title(): {
                            'id':
                            '08d2e326-377e-11e4-b531-3c15c2b8d2d6',
                            'links': [{
                                'href': 'www.mysite.com',
                                'rel': 'access_url'
                            }]
                        }
                    })
                service_controller = mock.Mock(create=return_mock)
                return mock.Mock(
                    obj=mock.Mock(provider_name=name.title(),
                                  service_controller=service_controller))

        providers.__getitem__.side_effect = get_provider_extension_by_name

        self.sc.storage_controller.get_service_limit = mock.Mock(
            return_value=self.max_services_per_project)

        self.sc.storage_controller.get_service_count = mock.Mock(
            return_value=1)

        service_obj = self.sc.create(self.project_id, self.auth_token,
                                     self.service_json)

        # ensure the manager calls the storage driver with the appropriate data
        self.sc.storage_controller.create.assert_called_once_with(
            self.project_id, service_obj)