def _run(self, a1key, has_default, has_rel, has_prop_key, has_chef_attr_key, expect_exception=None): merge_chef_attributes = { 'attr1': { } } merge_chef_attributes['attr1'][a1key] = 'prop1' if has_default: merge_chef_attributes['attr1'][ 'default_value'] = 'attr1_default_val' if has_rel: runtime_properties = {} if has_prop_key: runtime_properties['prop1'] = 'prop_val' if has_chef_attr_key: runtime_properties['chef_attributes'] = { 'prop1': 'chef_attr_val' } related = MockCloudifyContext( node_id='clodufiy_db_node_id_' + str(node_id.next()), runtime_properties=runtime_properties, ) else: related = None # print("MERGE_CHEF_ATTRIBUTES", merge_chef_attributes) ctx = _make_context( operation='install', merge_chef_attributes=merge_chef_attributes, related=related) # print("CTX", str(ctx), "RELATED", str(related)) if expect_exception: self.assertRaises( expect_exception, chef_client._prepare_chef_attributes, ctx) else: return chef_client._prepare_chef_attributes(ctx)
def test_deep(self): target = mocks.MockContext({ 'node': mocks.MockContext({'properties': {}}), 'instance': mocks.MockContext({ 'id': 'clodufiy_db_node_id_' + str(node_id.next()), 'runtime_properties': { 'chef_attributes': { 'a': { 'b': 7 } } } }) }) ctx = _make_context(operation='install', merge_chef_attributes={ 'attr2': { 'attr2b': { 'related_chef_attribute': 'a.b' } } }, target=target) # print("CTX", str(ctx), "RELATED", str(related)) v = chef_client._prepare_chef_attributes(ctx) self.assertIn('attr2', v) self.assertIn('attr2b', v['attr2']) self.assertEquals(v['attr2']['attr2b'], 7)
def test_deep(self): target = mocks.MockContext({ 'node': mocks.MockContext({ 'properties': {} }), 'instance': mocks.MockContext({ 'id': 'clodufiy_db_node_id_' + str(node_id.next()), 'runtime_properties': { 'chef_attributes': { 'a': { 'b': 7 } } } }) }) ctx = _make_context(operation='install', merge_chef_attributes={ 'attr2': { 'attr2b': { 'related_chef_attribute': 'a.b' } } }, target=target) # print("CTX", str(ctx), "RELATED", str(related)) v = chef_client._prepare_chef_attributes(ctx) self.assertIn('attr2', v) self.assertIn('attr2b', v['attr2']) self.assertEquals(v['attr2']['attr2b'], 7)
def _run(self, a1key, has_default, has_rel, has_prop_key, has_chef_attr_key, expect_exception=None): merge_chef_attributes = {'attr1': {}} merge_chef_attributes['attr1'][a1key] = 'prop1' if has_default: merge_chef_attributes['attr1'][ 'default_value'] = 'attr1_default_val' if has_rel: runtime_properties = {} if has_prop_key: runtime_properties['prop1'] = 'prop_val' if has_chef_attr_key: runtime_properties['chef_attributes'] = { 'prop1': 'chef_attr_val' } target = mocks.MockContext({ 'node': mocks.MockContext({'properties': {}}), 'instance': mocks.MockContext({ 'id': 'clodufiy_db_node_id_' + str(node_id.next()), 'runtime_properties': runtime_properties }) }) else: target = None # print("MERGE_CHEF_ATTRIBUTES", merge_chef_attributes) ctx = _make_context(operation='install', merge_chef_attributes=merge_chef_attributes, target=target) # print("CTX", str(ctx), "RELATED", str(related)) if expect_exception: self.assertRaises(expect_exception, chef_client._prepare_chef_attributes, ctx) else: return chef_client._prepare_chef_attributes(ctx)
def test_deep(self): related = MockCloudifyContext( node_id='clodufiy_db_node_id_' + str(node_id.next()), runtime_properties={'chef_attributes': { 'a': { 'b': 7 } }}, ) ctx = _make_context(operation='install', merge_chef_attributes={ 'attr2': { 'attr2b': { 'related_chef_attribute': 'a.b' } } }, related=related) # print("CTX", str(ctx), "RELATED", str(related)) v = chef_client._prepare_chef_attributes(ctx) self.assertIn('attr2', v) self.assertIn('attr2b', v['attr2']) self.assertEquals(v['attr2']['attr2b'], 7)
def test_deep(self): related = MockCloudifyContext( node_id='clodufiy_db_node_id_' + str(node_id.next()), runtime_properties={ 'chef_attributes': { 'a': { 'b': 7 } } }, ) ctx = _make_context(operation='install', merge_chef_attributes={ 'attr2': { 'attr2b': { 'related_chef_attribute': 'a.b' } } }, related=related) # print("CTX", str(ctx), "RELATED", str(related)) v = chef_client._prepare_chef_attributes(ctx) self.assertIn('attr2', v) self.assertIn('attr2b', v['attr2']) self.assertEquals(v['attr2']['attr2b'], 7)