Skip to content

Commit 7d2cd41

Browse files
CYBL-1527-Add-Flavor-ExtraSpecs-Access (#432)
1 parent 6ef0a96 commit 7d2cd41

File tree

8 files changed

+164
-3
lines changed

8 files changed

+164
-3
lines changed

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
3.3.5: add extra_specs and tenant access to flavor type.
12
3.3.4: support dsl 1_4 and redhat 8 wagons.
23
3.3.3: Bump openstacksdk to 0.53.0 to to fix server_groups attribute error
34
3.3.2: Re-releasing 3.3.1 for adding to bundle.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
tosca_definitions_version: cloudify_dsl_1_3
2+
3+
imports:
4+
- http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml
5+
- plugin:cloudify-openstack-plugin
6+
7+
inputs:
8+
9+
auth_url:
10+
type: string
11+
default: {get_secret: openstack_auth_url}
12+
13+
username:
14+
type: string
15+
default: {get_secret: openstack_username}
16+
17+
password:
18+
type: string
19+
default: {get_secret: openstack_password}
20+
21+
region_name:
22+
type: string
23+
default: {get_secret: region}
24+
25+
project_name:
26+
type: string
27+
default: 'default'
28+
29+
domain_name:
30+
type: string
31+
default: 'default'
32+
33+
flavor_config:
34+
default:
35+
name: { concat: [ { get_input: name_prefix }, 'flavor' ] }
36+
ram: 2048
37+
disk: 8
38+
vcpus: 2
39+
is_public: true
40+
41+
name_prefix:
42+
type: string
43+
default: compute-
44+
45+
user_domain_id:
46+
type: string
47+
default: default
48+
49+
flavor_extra_spec:
50+
default:
51+
"hw:cpu_policy": 'dedicated'
52+
"hw:cpu_threads_policy": 'isolate'
53+
54+
flavor_tenants:
55+
default: ['cfy_test_project']
56+
57+
dsl_definitions:
58+
59+
client_config: &client_config
60+
auth_url: { get_input: auth_url }
61+
username: { get_input: username }
62+
password: { get_input: password }
63+
region_name: { get_input: region_name }
64+
user_domain_name: { get_input: domain_name }
65+
project_domain_name: { get_input: project_name }
66+
67+
node_templates:
68+
69+
example-flavor:
70+
type: cloudify.nodes.openstack.Flavor
71+
properties:
72+
client_config: *client_config
73+
resource_config: { get_input: flavor_config }
74+
extra_specs: { get_input: flavor_extra_spec }
75+
tenants: { get_input: flavor_tenants }

openstack_plugin/resources/compute/flavor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def create(openstack_resource):
3535
"""
3636
created_resource = openstack_resource.create()
3737
ctx.instance.runtime_properties[RESOURCE_ID] = created_resource.id
38+
extra_specs = ctx.node.properties.get('extra_specs', {})
39+
tenants = ctx.node.properties.get('tenants', [])
40+
if extra_specs:
41+
openstack_resource.set_flavor_specs(created_resource.id, extra_specs)
42+
if tenants:
43+
for tenant in tenants:
44+
openstack_resource.add_flavor_access(created_resource.id, tenant)
3845

3946

4047
@with_compat_node

openstack_plugin/tests/compute/test_flavor.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,67 @@ def test_create(self, mock_connection):
7373
self._ctx.instance.runtime_properties[OPENSTACK_TYPE_PROPERTY],
7474
FLAVOR_OPENSTACK_TYPE)
7575

76+
mock_connection().compute.create_flavor_extra_specs.assert_not_called()
77+
78+
mock_connection().compute.flavor_add_tenant_access.assert_not_called()
79+
80+
def test_create_extra_specs_access(self, mock_connection):
81+
# Prepare the context for create operation
82+
self._prepare_context_for_operation(
83+
test_name='FlavorTestCaseExtraSpecsAcess',
84+
test_properties={
85+
'client_config': self.client_config,
86+
'resource_config': {
87+
'name': 'test_flavor',
88+
'ram': 2048,
89+
'disk': 8,
90+
'vcpus': 2,
91+
'is_public': False
92+
},
93+
'extra_specs': {
94+
'hw:cpu_policy': 'dedicated',
95+
'hw:cpu_threads_policy': 'isolate'
96+
},
97+
'tenants': ['cfy_test_project']
98+
},
99+
ctx_operation_name='cloudify.interfaces.lifecycle.create')
100+
101+
flavor_instance = openstack.compute.v2.flavor.Flavor(**{
102+
'id': 'a95b5509-c122-4c2f-823e-884bb559afe8',
103+
'name': 'test_flavor',
104+
'links': '2',
105+
'os-flavor-access:is_public': False,
106+
'ram': 2048,
107+
'vcpus': 2,
108+
'disk': 8
109+
})
110+
111+
mock_connection().compute.create_flavor = \
112+
mock.MagicMock(return_value=flavor_instance)
113+
114+
mock_connection().compute.create_flavor_extra_specs = \
115+
mock.Mock()
116+
117+
mock_connection().identity.find_project = \
118+
mock.Mock()
119+
120+
mock_connection().compute.flavor_add_tenant_access = \
121+
mock.Mock()
122+
123+
# Call create flavor
124+
flavor.create(openstack_resource=None)
125+
126+
self.assertEqual(self._ctx.instance.runtime_properties[RESOURCE_ID],
127+
'a95b5509-c122-4c2f-823e-884bb559afe8')
128+
129+
self.assertEqual(
130+
self._ctx.instance.runtime_properties[OPENSTACK_NAME_PROPERTY],
131+
'test_flavor')
132+
133+
mock_connection().compute.create_flavor_extra_specs.assert_called()
134+
135+
mock_connection().compute.flavor_add_tenant_access.assert_called()
136+
76137
def test_delete(self, mock_connection):
77138
# Prepare the context for delete operation
78139
self._prepare_context_for_operation(

openstack_sdk/resources/compute.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,20 @@ def delete(self):
487487
self.logger.debug(
488488
'Deleted flavor with this result: {0}'.format(result))
489489
return result
490+
491+
def set_flavor_specs(self, flavor_id, extra_specs):
492+
self.logger.debug(
493+
'Attempting to set flavor {0} specs with these args: {1}'.format(
494+
flavor_id, extra_specs))
495+
496+
self.connection.compute.create_flavor_extra_specs(flavor_id,
497+
extra_specs)
498+
499+
def add_flavor_access(self, flavor_id, tenant):
500+
self.logger.debug(
501+
'Attempting to set flavor {0} access with these args: {1}'.format(
502+
flavor_id, tenant))
503+
project = self.connection.identity.find_project(tenant,
504+
ignore_missing=False)
505+
self.connection.compute.flavor_add_tenant_access(flavor_id,
506+
project.id)

plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
openstack:
44
executor: central_deployment_agent
55
package_name: cloudify-openstack-plugin
6-
package_version: '3.3.4'
6+
package_version: '3.3.5'
77

88
dsl_definitions:
99

plugin_1_4.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
openstack:
44
executor: central_deployment_agent
55
package_name: cloudify-openstack-plugin
6-
package_version: '3.3.4'
6+
package_version: '3.3.5'
77

88
dsl_definitions:
99

v2_plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins:
33
openstack:
44
executor: central_deployment_agent
55
package_name: cloudify-openstack-plugin
6-
package_version: '3.3.4'
6+
package_version: '3.3.5'
77

88
dsl_definitions:
99

0 commit comments

Comments
 (0)