Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resource_id and is_external properties #1238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions cloudify/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# * See the License for the specific language governing permissions and
# * limitations under the License.

import errno
import os
import errno
import warnings
from contextlib import contextmanager

from cloudify_rest_client.exceptions import CloudifyClientError
from cloudify.endpoint import ManagerEndpoint, LocalEndpoint
from cloudify.logs import init_cloudify_logger
from cloudify import utils
from cloudify import constants
from cloudify import exceptions
from cloudify import utils
from cloudify.logs import init_cloudify_logger
from cloudify.endpoint import ManagerEndpoint, LocalEndpoint
from cloudify_rest_client.exceptions import CloudifyClientError
from cloudify.constants import DEPLOYMENT, NODE_INSTANCE, RELATIONSHIP_INSTANCE


Expand Down Expand Up @@ -404,7 +404,10 @@ def properties(self):
These properties are the properties specified in the blueprint.
"""
self._get_node_if_needed()
return self._node.properties
try:
return self._node.properties
except AttributeError:
return self._node.get('properties')
Comment on lines +407 to +410
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary (other than in test)?


@property
def type(self):
Expand All @@ -424,6 +427,16 @@ def number_of_instances(self):
self._get_node_if_needed()
return self._node.number_of_instances

@property
def is_external(self) -> bool:
"""If this is a resource that Cloudify manages or not"""
return self.properties.get('use_external_resource', False)

@property
def resource_id(self):
"""The resource's ID outside of Cloudify"""
return self.properties.get('resource_id')


class NodeInstanceContext(EntityContext):
def __init__(self, *args, **kwargs):
Expand Down
26 changes: 25 additions & 1 deletion cloudify/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def setUp(self):
os.environ[constants.LOCAL_RESOURCES_ROOT_ENV_KEY] = '/tmp/resources'
self.context = context.CloudifyContext({
'blueprint_id': '',
'tenant': {'name': 'default_tenant'}
'tenant': {'name': 'default_tenant'},
'properties': {
'use_external_resource': False,
'resource_id': 'foo'
}
})
# the context logger will try to publish messages to rabbit, which is
# not available here. instead, we redirect the output to stdout.
Expand Down Expand Up @@ -318,6 +322,26 @@ def test_source_target_not_in_relationship(self):
'relationship-instance context but used in a '
'deployment context.', str(cm.exception))

def test_node_ctx_properties(self):

def get_node_mock(*_, **__):
return {
'properties': {
'use_external_resource': False,
'resource_id': 'foo'
}
}

endpoint = Mock()
endpoint.get_node = get_node_mock
kwargs = {
'endpoint': endpoint,
'context': {'node_id': 'node_id'},
}
ctx_node = context.NodeContext(**kwargs)
self.assertFalse(ctx_node.is_external)
self.assertEqual(ctx_node.resource_id, 'foo')

def test_ctx_type(self):
ctx = context.CloudifyContext({})
self.assertEqual(constants.DEPLOYMENT, ctx.type)
Expand Down
Binary file not shown.
Empty file added dev-requirements.txt
Empty file.