Exemplo n.º 1
0
    def test_load_template_use_neutron(self):
        """This test checks Heat cluster template with Neutron enabled.
           Two NodeGroups used: 'master' with Ephemeral drive attached and
           'worker' with 2 attached volumes 10GB size each
        """

        ng1 = tu._make_ng_dict('master', 42, ['namenode'], 1,
                               floating_ip_pool='floating', image_id=None,
                               volumes_per_node=0, volumes_size=0, id=1)
        ng2 = tu._make_ng_dict('worker', 42, ['datanode'], 1,
                               floating_ip_pool='floating', image_id=None,
                               volumes_per_node=2, volumes_size=10, id=2)
        cluster = tu._create_cluster("cluster", "tenant1", "general",
                                     "1.2.1", [ng1, ng2],
                                     user_keypair_id='user_key',
                                     neutron_management_network='private_net',
                                     default_image_id='1', anti_affinity=[],
                                     image_id=None)
        heat_template = h.ClusterTemplate(cluster)
        heat_template.add_node_group_extra(ng1['id'], 1, 'line1\nline2')
        heat_template.add_node_group_extra(ng2['id'], 1, 'line2\nline3')

        h.CONF.set_override("use_neutron", True)
        try:
            main_template = h._load_template(
                'main.heat', {'resources':
                              heat_template._serialize_resources()})

            self.assertEqual(
                json.loads(main_template),
                json.loads(f.get_file_text(
                    "tests/unit/resources/"
                    "test_serialize_resources_use_neutron.heat")))
        finally:
            h.CONF.clear_override("use_neutron")
Exemplo n.º 2
0
    def test_load_template_with_anti_affinity_single_ng(self):
        """This test checks Heat cluster template with Neutron enabled
           and anti-affinity feature enabled for single node process
           in single node group.
        """

        ng1 = tu._make_ng_dict('master', 42, ['namenode'], 1,
                               floating_ip_pool='floating', image_id=None,
                               volumes_per_node=0, volumes_size=0, id=1)
        ng2 = tu._make_ng_dict('worker', 42, ['datanode'], 2,
                               floating_ip_pool='floating', image_id=None,
                               volumes_per_node=0, volumes_size=0, id=2)
        cluster = tu._create_cluster("cluster", "tenant1", "general",
                                     "1.2.1", [ng1, ng2],
                                     user_keypair_id='user_key',
                                     neutron_management_network='private_net',
                                     default_image_id='1',
                                     anti_affinity=['datanode'], image_id=None)
        aa_heat_template = h.ClusterTemplate(cluster)
        aa_heat_template.add_node_group_extra(ng1['id'], 1, 'line1\nline2')
        aa_heat_template.add_node_group_extra(ng2['id'], 2, 'line2\nline3')

        h.CONF.use_neutron = True

        main_template = h._load_template(
            'main.heat', {'resources':
                          aa_heat_template._serialize_resources()})

        self.assertEqual(
            json.loads(main_template),
            json.loads(f.get_file_text(
                "tests/unit/resources/"
                "test_serialize_resources_aa.heat")))
Exemplo n.º 3
0
    def _validate_case(self, *args):
        lst = []
        for i in range(0, len(args)):
            self.ng[i]['count'] = args[i]
            lst.append(self.ng[i])

        cl = tu._create_cluster("cluster1", "tenant1", "vanilla", "1.2.1", lst)

        self.pl.validate(cl)
    def test_check_cluster_scaling_resize_ng(self):
        ng1 = tu._make_ng_dict('ng', '42', ['namenode'], 1)
        cluster = tu._create_cluster("cluster1", "tenant1", "vanilla", "1.2.1",
                                     [ng1], status='Validating', id='12321')

        self._assert_check_scaling(data={}, cluster=cluster,
                                   expected_message=
                                   "Cluster cannot be scaled "
                                   "not in 'Active' "
                                   "status. Cluster status: "
                                   "Validating")

        cluster = tu._create_cluster("cluster1", "tenant1", "vanilla", "1.2.1",
                                     [ng1], status='Active', id='12321')
        data = {
            'resize_node_groups': [
                {
                    'name': 'a',
                    'flavor_id': '42',
                    'node_processes': ['namenode']
                }
            ],
        }
        self._assert_check_scaling(data=data, cluster=cluster,
                                   expected_message=
                                   "Cluster doesn't contain "
                                   "node group with name 'a'")
        data.update({'resize_node_groups': [
            {
                'name': 'a',
                'flavor_id': '42',
                'node_processes': ['namenode']
            },
            {
                'name': 'a',
                'flavor_id': '42',
                'node_processes': ['namenode']
            }
        ]})
        self._assert_check_scaling(data=data, cluster=cluster,
                                   expected_message=
                                   'Duplicates in node '
                                   'group names are detected')
 def test_check_cluster_scaling_add_ng(self):
     ng1 = tu._make_ng_dict('ng', '42', ['namenode'], 1)
     cluster = tu._create_cluster("test-cluster", "tenant", "vanilla",
                                  "1.2.2", [ng1], status='Active',
                                  id='12321')
     data = {
         'add_node_groups': [
             {
                 'name': 'a',
                 'flavor_id': '42',
                 'node_processes': ['namenode']
             },
             {
                 'name': 'a',
                 'flavor_id': '42',
                 'node_processes': ['namenode']
             }
         ]
     }
     self._assert_check_scaling(data=data, cluster=cluster,
                                expected_message=
                                'Duplicates in node '
                                'group names are detected')
     data = {
         'add_node_groups': [
             {
                 'name': 'ng',
                 'flavor_id': '42',
                 'node_processes': ['namenode']
             },
         ]
     }
     self._assert_check_scaling(data=data, cluster=cluster,
                                expected_message=
                                "Can't add new nodegroup. "
                                "Cluster already has nodegroup "
                                "with name 'ng'")
Exemplo n.º 6
0
def start_patch(patch_templates=True):
    get_clusters_p = mock.patch("savanna.service.api.get_clusters")
    get_cluster_p = mock.patch("savanna.service.api.get_cluster")
    if patch_templates:
        get_ng_templates_p = \
            mock.patch("savanna.service.api.get_node_group_templates")
        get_ng_template_p = \
            mock.patch("savanna.service.api.get_node_group_template")
    get_plugins_p = mock.patch("savanna.service.api.get_plugins")
    get_plugin_p = \
        mock.patch("savanna.plugins.base.PluginManager.get_plugin")
    if patch_templates:
        get_cl_templates_p = \
            mock.patch("savanna.service.api.get_cluster_templates")
        get_cl_template_p = \
            mock.patch("savanna.service.api.get_cluster_template")
    nova_p = mock.patch("savanna.utils.openstack.nova.client")
    keystone_p = mock.patch("savanna.utils.openstack.keystone.client")
    get_image_p = mock.patch("savanna.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

    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.2', [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.2',
                    #'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.2'}

        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_plugins_p, get_plugin_p,
                nova_p, keystone_p, get_image_p]
    if patch_templates:
        patchers.extend([get_ng_template_p, get_ng_templates_p,
                         get_cl_template_p, get_cl_templates_p])
    return patchers