def setUp(self): super(TestUtils, self).setUp() self.plugin = p.VanillaProvider() self.ng_manager = tu.make_ng_dict( 'mng', 'f1', ['manager'], 1, [tu.make_inst_dict('mng1', 'manager')]) self.ng_namenode = tu.make_ng_dict( 'nn', 'f1', ['namenode'], 1, [tu.make_inst_dict('nn1', 'namenode')]) self.ng_jobtracker = tu.make_ng_dict( 'jt', 'f1', ['jobtracker'], 1, [tu.make_inst_dict('jt1', 'jobtracker')]) self.ng_datanode = tu.make_ng_dict('dn', 'f1', ['datanode'], 2, [ tu.make_inst_dict('dn1', 'datanode-1'), tu.make_inst_dict('dn2', 'datanode-2') ]) self.ng_tasktracker = tu.make_ng_dict('tt', 'f1', ['tasktracker'], 2, [ tu.make_inst_dict('tt1', 'tasktracker-1'), tu.make_inst_dict('tt2', 'tasktracker-2') ]) self.ng_oozie = tu.make_ng_dict('ooz1', 'f1', ['oozie'], 1, [tu.make_inst_dict('ooz1', 'oozie')]) self.ng_hiveserver = tu.make_ng_dict( 'hs', 'f1', ['hiveserver'], 1, [tu.make_inst_dict('hs1', 'hiveserver')]) self.ng_secondarynamenode = tu.make_ng_dict( 'snn', 'f1', ['secondarynamenode'], 1, [tu.make_inst_dict('snn1', 'secondarynamenode')])
def setUp(self): super(VanillaPluginTest, self).setUp() self.pl = p.VanillaProvider()
def _get_plugin(plugin_name): if plugin_name == 'vanilla': return plugin.VanillaProvider() return None
def setUp(self): super(ValidationTest, self).setUp() self.pl = p.VanillaProvider()
def start_patch(patch_templates=True): get_clusters_p = mock.patch("sahara.service.api.get_clusters") get_cluster_p = mock.patch("sahara.service.api.get_cluster") if patch_templates: get_ng_templates_p = \ mock.patch("sahara.service.api.get_node_group_templates") get_ng_template_p = \ mock.patch("sahara.service.api.get_node_group_template") get_plugins_p = mock.patch("sahara.service.api.get_plugins") get_plugin_p = \ mock.patch("sahara.plugins.base.PluginManager.get_plugin") if patch_templates: get_cl_templates_p = \ mock.patch("sahara.service.api.get_cluster_templates") get_cl_template_p = \ mock.patch("sahara.service.api.get_cluster_template") nova_p = mock.patch("sahara.utils.openstack.nova.client") keystone_p = mock.patch("sahara.utils.openstack.keystone.client") heat_p = mock.patch("sahara.utils.openstack.heat.client") get_image_p = mock.patch("sahara.service.api.get_image") get_image = get_image_p.start() get_clusters = get_clusters_p.start() get_cluster = get_cluster_p.start() if patch_templates: get_ng_templates = get_ng_templates_p.start() get_ng_template = get_ng_template_p.start() get_plugins = get_plugins_p.start() get_plugin = get_plugin_p.start() if patch_templates: get_cl_templates = get_cl_templates_p.start() get_cl_template_p.start() nova = nova_p.start() keystone = keystone_p.start() if patch_templates: get_cl_templates.return_value = [] nova().flavors.list.side_effect = _get_flavors_list nova().keypairs.get.side_effect = _get_keypair nova().networks.find.side_effect = _get_network nova().floating_ip_pools.list.side_effect = _get_fl_ip_pool_list heat = heat_p.start() heat().stacks.list.side_effect = _get_heat_stack_list class Service: @property def name(self): return 'cinder' def _services_list(): return [Service()] keystone().services.list.side_effect = _services_list class Image: def __init__(self, name='test'): self.name = name @property def id(self): if self.name == 'test': return '550e8400-e29b-41d4-a716-446655440000' else: return '813fe450-40d2-4acc-ade5-ea753a1bd5bc' @property def tags(self): if self.name == 'test': return ['vanilla', '1.2.1'] else: return ['wrong_tag'] def _get_image(id): if id == '550e8400-e29b-41d4-a716-446655440000': return Image() else: return Image('wrong_test') get_image.side_effect = _get_image nova().images.list_registered.return_value = [ Image(), Image(name='wrong_name') ] ng_dict = tu.make_ng_dict('ng', '42', ['namenode'], 1) cluster = tu.create_cluster('test', 't', 'vanilla', '1.2.1', [ng_dict], id=1, status='Active') # stub clusters list get_clusters.return_value = [cluster] get_cluster.return_value = cluster # stub node templates if patch_templates: ngt_dict = { 'name': 'test', 'tenant_id': 't', 'flavor_id': '42', 'plugin_name': 'vanilla', 'hadoop_version': '1.2.1', #'id': '1234321', 'id': '550e8400-e29b-41d4-a716-446655440000', 'node_processes': ['namenode'] } get_ng_templates.return_value = [r.NodeGroupTemplateResource(ngt_dict)] ct_dict = { 'name': 'test', 'tenant_id': 't', 'plugin_name': 'vanilla', 'hadoop_version': '1.2.1' } get_cl_templates.return_value = [r.ClusterTemplateResource(ct_dict)] vanilla = plugin.VanillaProvider() vanilla.name = 'vanilla' get_plugins.return_value = [vanilla] def _get_ng_template(id): for template in get_ng_templates(): if template.id == id: return template return None def _get_plugin(name): if name == 'vanilla': return vanilla return None get_plugin.side_effect = _get_plugin if patch_templates: get_ng_template.side_effect = _get_ng_template # request data to validate patchers = [ get_clusters_p, get_cluster_p, get_plugins_p, get_plugin_p, nova_p, keystone_p, get_image_p, heat_p ] if patch_templates: patchers.extend([ get_ng_template_p, get_ng_templates_p, get_cl_template_p, get_cl_templates_p ]) return patchers