Skip to content

Commit

Permalink
CYBL-1527-Add-Flavor-ExtraSpecs-Access (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadiesa-abu authored Mar 6, 2023
1 parent 6ef0a96 commit 7d2cd41
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
3.3.5: add extra_specs and tenant access to flavor type.
3.3.4: support dsl 1_4 and redhat 8 wagons.
3.3.3: Bump openstacksdk to 0.53.0 to to fix server_groups attribute error
3.3.2: Re-releasing 3.3.1 for adding to bundle.
Expand Down
75 changes: 75 additions & 0 deletions examples/local/flavor_with_extra_specs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
tosca_definitions_version: cloudify_dsl_1_3

imports:
- http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml
- plugin:cloudify-openstack-plugin

inputs:

auth_url:
type: string
default: {get_secret: openstack_auth_url}

username:
type: string
default: {get_secret: openstack_username}

password:
type: string
default: {get_secret: openstack_password}

region_name:
type: string
default: {get_secret: region}

project_name:
type: string
default: 'default'

domain_name:
type: string
default: 'default'

flavor_config:
default:
name: { concat: [ { get_input: name_prefix }, 'flavor' ] }
ram: 2048
disk: 8
vcpus: 2
is_public: true

name_prefix:
type: string
default: compute-

user_domain_id:
type: string
default: default

flavor_extra_spec:
default:
"hw:cpu_policy": 'dedicated'
"hw:cpu_threads_policy": 'isolate'

flavor_tenants:
default: ['cfy_test_project']

dsl_definitions:

client_config: &client_config
auth_url: { get_input: auth_url }
username: { get_input: username }
password: { get_input: password }
region_name: { get_input: region_name }
user_domain_name: { get_input: domain_name }
project_domain_name: { get_input: project_name }

node_templates:

example-flavor:
type: cloudify.nodes.openstack.Flavor
properties:
client_config: *client_config
resource_config: { get_input: flavor_config }
extra_specs: { get_input: flavor_extra_spec }
tenants: { get_input: flavor_tenants }
7 changes: 7 additions & 0 deletions openstack_plugin/resources/compute/flavor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def create(openstack_resource):
"""
created_resource = openstack_resource.create()
ctx.instance.runtime_properties[RESOURCE_ID] = created_resource.id
extra_specs = ctx.node.properties.get('extra_specs', {})
tenants = ctx.node.properties.get('tenants', [])
if extra_specs:
openstack_resource.set_flavor_specs(created_resource.id, extra_specs)
if tenants:
for tenant in tenants:
openstack_resource.add_flavor_access(created_resource.id, tenant)


@with_compat_node
Expand Down
61 changes: 61 additions & 0 deletions openstack_plugin/tests/compute/test_flavor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,67 @@ def test_create(self, mock_connection):
self._ctx.instance.runtime_properties[OPENSTACK_TYPE_PROPERTY],
FLAVOR_OPENSTACK_TYPE)

mock_connection().compute.create_flavor_extra_specs.assert_not_called()

mock_connection().compute.flavor_add_tenant_access.assert_not_called()

def test_create_extra_specs_access(self, mock_connection):
# Prepare the context for create operation
self._prepare_context_for_operation(
test_name='FlavorTestCaseExtraSpecsAcess',
test_properties={
'client_config': self.client_config,
'resource_config': {
'name': 'test_flavor',
'ram': 2048,
'disk': 8,
'vcpus': 2,
'is_public': False
},
'extra_specs': {
'hw:cpu_policy': 'dedicated',
'hw:cpu_threads_policy': 'isolate'
},
'tenants': ['cfy_test_project']
},
ctx_operation_name='cloudify.interfaces.lifecycle.create')

flavor_instance = openstack.compute.v2.flavor.Flavor(**{
'id': 'a95b5509-c122-4c2f-823e-884bb559afe8',
'name': 'test_flavor',
'links': '2',
'os-flavor-access:is_public': False,
'ram': 2048,
'vcpus': 2,
'disk': 8
})

mock_connection().compute.create_flavor = \
mock.MagicMock(return_value=flavor_instance)

mock_connection().compute.create_flavor_extra_specs = \
mock.Mock()

mock_connection().identity.find_project = \
mock.Mock()

mock_connection().compute.flavor_add_tenant_access = \
mock.Mock()

# Call create flavor
flavor.create(openstack_resource=None)

self.assertEqual(self._ctx.instance.runtime_properties[RESOURCE_ID],
'a95b5509-c122-4c2f-823e-884bb559afe8')

self.assertEqual(
self._ctx.instance.runtime_properties[OPENSTACK_NAME_PROPERTY],
'test_flavor')

mock_connection().compute.create_flavor_extra_specs.assert_called()

mock_connection().compute.flavor_add_tenant_access.assert_called()

def test_delete(self, mock_connection):
# Prepare the context for delete operation
self._prepare_context_for_operation(
Expand Down
17 changes: 17 additions & 0 deletions openstack_sdk/resources/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,20 @@ def delete(self):
self.logger.debug(
'Deleted flavor with this result: {0}'.format(result))
return result

def set_flavor_specs(self, flavor_id, extra_specs):
self.logger.debug(
'Attempting to set flavor {0} specs with these args: {1}'.format(
flavor_id, extra_specs))

self.connection.compute.create_flavor_extra_specs(flavor_id,
extra_specs)

def add_flavor_access(self, flavor_id, tenant):
self.logger.debug(
'Attempting to set flavor {0} access with these args: {1}'.format(
flavor_id, tenant))
project = self.connection.identity.find_project(tenant,
ignore_missing=False)
self.connection.compute.flavor_add_tenant_access(flavor_id,
project.id)
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins:
openstack:
executor: central_deployment_agent
package_name: cloudify-openstack-plugin
package_version: '3.3.4'
package_version: '3.3.5'

dsl_definitions:

Expand Down
2 changes: 1 addition & 1 deletion plugin_1_4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins:
openstack:
executor: central_deployment_agent
package_name: cloudify-openstack-plugin
package_version: '3.3.4'
package_version: '3.3.5'

dsl_definitions:

Expand Down
2 changes: 1 addition & 1 deletion v2_plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins:
openstack:
executor: central_deployment_agent
package_name: cloudify-openstack-plugin
package_version: '3.3.4'
package_version: '3.3.5'

dsl_definitions:

Expand Down

0 comments on commit 7d2cd41

Please sign in to comment.