示例#1
0
    def test_one_node_groups_and_one_affinity_group(self, novaclient):
        node_groups = [_make_ng_dict('test_group', 'test_flavor',
                                     ['data node'], 2)]
        cluster = _create_cluster_mock(node_groups, ["data node"])
        nova = _create_nova_mock(novaclient)
        instances._create_instances(cluster)
        userdata = _generate_user_data_script(cluster)

        nova.servers.create.assert_has_calls(
            [mock.call("test_cluster-test_group-001",
                       "initial",
                       "test_flavor",
                       scheduler_hints=None,
                       userdata=userdata,
                       key_name='user_keypair'),
             mock.call("test_cluster-test_group-002",
                       "initial",
                       "test_flavor",
                       scheduler_hints={'different_host': ["1"]},
                       userdata=userdata,
                       key_name='user_keypair')],
            any_order=False)

        ctx = context.ctx()
        cluster_obj = conductor.cluster_get_all(ctx)[0]
        self.assertEqual(len(cluster_obj.node_groups[0].instances), 2)
示例#2
0
    def test_one_node_groups_and_no_affinity_group(self, novaclient):
        node_groups = [_make_ng_dict("test_group", "test_flavor", ["data node", "task tracker"], 2)]

        cluster = _create_cluster_mock(node_groups, [])
        nova = _create_nova_mock(novaclient)
        instances._create_instances(cluster)
        userdata = _generate_user_data_script(cluster)

        nova.servers.create.assert_has_calls(
            [
                mock.call(
                    "test_cluster-test_group-001",
                    "initial",
                    "test_flavor",
                    scheduler_hints=None,
                    userdata=userdata,
                    key_name="user_keypair",
                ),
                mock.call(
                    "test_cluster-test_group-002",
                    "initial",
                    "test_flavor",
                    scheduler_hints=None,
                    userdata=userdata,
                    key_name="user_keypair",
                ),
            ],
            any_order=False,
        )

        ctx = context.ctx()
        cluster_obj = conductor.cluster_get_all(ctx)[0]
        self.assertEqual(len(cluster_obj.node_groups[0].instances), 2)
示例#3
0
    def test_one_node_groups_and_no_affinity_group(self, novaclient):
        node_groups = [m.NodeGroup("test_group", "test_flavor",
                                   ["data node", "test tracker"], 2)]
        node_groups[0]._username = "******"
        cluster = _create_cluster_mock(node_groups, [])
        nova = _create_nova_mock(novaclient)
        instances._create_instances(cluster)
        userdata = _generate_user_data_script(cluster)

        nova.servers.create.assert_has_calls(
            [mock.call("test_cluster-test_group-001",
                       "initial",
                       "test_flavor",
                       scheduler_hints=None,
                       userdata=userdata,
                       key_name='user_keypair'),
             mock.call("test_cluster-test_group-002",
                       "initial",
                       "test_flavor",
                       scheduler_hints=None,
                       userdata=userdata,
                       key_name='user_keypair')],
            any_order=False)

        session = ctx.ctx().session
        with session.begin():
            self.assertEqual(session.query(m.Instance).count(), 2)
示例#4
0
    def test_ip_assignment_use_no_floating(self, cfg, novaclient):

        cfg.CONF.use_floating_ips = False
        nova = _create_nova_mock(novaclient)

        node_groups = [_make_ng_dict("test_group_1", "test_flavor",
                                     ["data node", "test tracker"], 2, 'pool'),
                       _make_ng_dict("test_group_2", "test_flavor",
                                     ["name node", "test tracker"], 1)]

        ctx = context.ctx()
        cluster = _create_cluster_mock(node_groups, ["data node"])
        instances._create_instances(cluster)

        cluster = conductor.cluster_get(ctx, cluster)
        instances_list = instances._get_instances(cluster)

        instances._assign_floating_ips(instances_list)

        nova.floating_ips.create.assert_has_calls(
            [mock.call("pool"),
             mock.call("pool")],
            any_order=False
        )

        self.assertEqual(nova.floating_ips.create.call_count, 2,
                         "Not expected floating IPs number found.")
示例#5
0
    def test_one_node_groups_and_no_affinity_group(self, novaclient):
        node_groups = [
            _make_ng_dict('test_group', 'test_flavor',
                          ['data node', 'task tracker'], 2)
        ]

        cluster = _create_cluster_mock(node_groups, [])
        nova = _create_nova_mock(novaclient)
        instances._create_instances(cluster)
        userdata = _generate_user_data_script(cluster)

        nova.servers.create.assert_has_calls([
            mock.call("test_cluster-test_group-001",
                      "initial",
                      "test_flavor",
                      scheduler_hints=None,
                      userdata=userdata,
                      key_name='user_keypair'),
            mock.call("test_cluster-test_group-002",
                      "initial",
                      "test_flavor",
                      scheduler_hints=None,
                      userdata=userdata,
                      key_name='user_keypair')
        ],
                                             any_order=False)

        ctx = context.ctx()
        cluster_obj = conductor.cluster_get_all(ctx)[0]
        self.assertEqual(len(cluster_obj.node_groups[0].instances), 2)
示例#6
0
    def test_ip_assignment_use_no_floating(self, cfg, novaclient):

        cfg.CONF.use_floating_ips = False
        nova = _create_nova_mock(novaclient)

        node_groups = [
            _make_ng_dict("test_group_1", "test_flavor",
                          ["data node", "test tracker"], 2, 'pool'),
            _make_ng_dict("test_group_2", "test_flavor",
                          ["name node", "test tracker"], 1)
        ]

        ctx = context.ctx()
        cluster = _create_cluster_mock(node_groups, ["data node"])
        instances._create_instances(cluster)

        cluster = conductor.cluster_get(ctx, cluster)
        instances_list = instances.get_instances(cluster)

        instances._assign_floating_ips(instances_list)

        nova.floating_ips.create.assert_has_calls(
            [mock.call("pool"), mock.call("pool")], any_order=False)

        self.assertEqual(nova.floating_ips.create.call_count, 2,
                         "Not expected floating IPs number found.")
示例#7
0
    def test_two_node_groups_and_one_affinity_group(self, novaclient):
        node_groups = [
            _make_ng_dict("test_group_1", "test_flavor", ["data node", "test tracker"], 2),
            _make_ng_dict("test_group_2", "test_flavor", ["data node", "test tracker"], 1),
        ]

        cluster = _create_cluster_mock(node_groups, ["data node"])
        nova = _create_nova_mock(novaclient)
        instances._create_instances(cluster)
        userdata = _generate_user_data_script(cluster)

        nova.servers.create.assert_has_calls(
            [
                mock.call(
                    "test_cluster-test_group_1-001",
                    "initial",
                    "test_flavor",
                    scheduler_hints=None,
                    userdata=userdata,
                    key_name="user_keypair",
                ),
                mock.call(
                    "test_cluster-test_group_1-002",
                    "initial",
                    "test_flavor",
                    scheduler_hints={"different_host": ["1"]},
                    userdata=userdata,
                    key_name="user_keypair",
                ),
                mock.call(
                    "test_cluster-test_group_2-001",
                    "initial",
                    "test_flavor",
                    scheduler_hints={"different_host": ["1", "2"]},
                    userdata=userdata,
                    key_name="user_keypair",
                ),
            ],
            any_order=False,
        )

        ctx = context.ctx()
        cluster_obj = conductor.cluster_get_all(ctx)[0]
        inst_number = len(cluster_obj.node_groups[0].instances)
        inst_number += len(cluster_obj.node_groups[1].instances)
        self.assertEqual(inst_number, 3)
示例#8
0
    def test_delete_floating_ips(self, novaclient):

        nova = _create_nova_mock(novaclient)

        node_groups = [_make_ng_dict("test_group_1", "test_flavor",
                                     ["data node", "test tracker"], 2, 'pool')]

        ctx = context.ctx()
        cluster = _create_cluster_mock(node_groups, ["datanode"])
        instances._create_instances(cluster)

        cluster = conductor.cluster_get(ctx, cluster)
        instances_list = instances._get_instances(cluster)

        instances._assign_floating_ips(instances_list)

        instances._shutdown_instances(cluster)
        self.assertEqual(nova.floating_ips.delete.call_count, 2,
                         "Not expected floating IPs number found in delete")
        self.assertEqual(nova.servers.delete.call_count, 2,
                         "Not expected")
示例#9
0
    def test_two_node_groups_and_one_affinity_group(self, novaclient):
        node_groups = [
            _make_ng_dict("test_group_1", "test_flavor",
                          ["data node", "test tracker"], 2),
            _make_ng_dict("test_group_2", "test_flavor",
                          ["data node", "test tracker"], 1)
        ]

        cluster = _create_cluster_mock(node_groups, ["data node"])
        nova = _create_nova_mock(novaclient)
        instances._create_instances(cluster)
        userdata = _generate_user_data_script(cluster)

        nova.servers.create.assert_has_calls([
            mock.call("test_cluster-test_group_1-001",
                      "initial",
                      "test_flavor",
                      scheduler_hints=None,
                      userdata=userdata,
                      key_name='user_keypair'),
            mock.call("test_cluster-test_group_1-002",
                      "initial",
                      "test_flavor",
                      scheduler_hints={'different_host': ["1"]},
                      userdata=userdata,
                      key_name='user_keypair'),
            mock.call("test_cluster-test_group_2-001",
                      "initial",
                      "test_flavor",
                      scheduler_hints={'different_host': ["1", "2"]},
                      userdata=userdata,
                      key_name='user_keypair')
        ],
                                             any_order=False)

        ctx = context.ctx()
        cluster_obj = conductor.cluster_get_all(ctx)[0]
        inst_number = len(cluster_obj.node_groups[0].instances)
        inst_number += len(cluster_obj.node_groups[1].instances)
        self.assertEqual(inst_number, 3)