Exemple #1
0
    def cluster_update(self, context, cluster, values):
        """Set the given properties on cluster and update it."""
        values = copy.deepcopy(values)
        update_shares = values.get('shares')
        if update_shares:
            original_shares = (self.db.cluster_get(context,
                                                   cluster).get('shares', []))

        updated_cluster = self.db.cluster_update(context, cluster, values)
        if update_shares:
            for share in update_shares:
                # Only call mount_shares if we have new shares to mount.
                # We only need one positive case to bother calling mount_shares
                if share not in original_shares:
                    shares.mount_shares(r.ClusterResource(updated_cluster))
                    break
            # Any shares that were on the original, but not on the updated
            # list will be unmounted
            unmount_list = [
                share for share in original_shares
                if share not in update_shares
            ]
            if len(unmount_list) > 0:
                shares.unmount_shares(r.ClusterResource(updated_cluster),
                                      unmount_list)

        return updated_cluster
Exemple #2
0
    def test_attach(self, p_create_attach_vol,
                    p_await, p_mount):
        p_create_attach_vol.side_effect = ['/dev/vdb', '/dev/vdc'] * 2
        p_await.return_value = None
        p_mount.return_value = None

        instance1 = {'id': '1',
                     'instance_id': '123',
                     'instance_name': 'inst_1'}
        instance2 = {'id': '2',
                     'instance_id': '456',
                     'instance_name': 'inst_2'}

        ng = {'volumes_per_node': 2,
              'volumes_size': 2,
              'volume_mount_prefix': '/mnt/vols',
              'name': 'master',
              'instances': [instance1, instance2]}

        cluster = r.ClusterResource({'node_groups': [ng]})

        volumes.attach_to_instances(g.get_instances(cluster))
        self.assertEqual(p_create_attach_vol.call_count, 4)
        self.assertEqual(p_await.call_count, 2)
        self.assertEqual(p_mount.call_count, 4)
Exemple #3
0
    def test_to_dict_filtering(self):
        cluster_dict = copy.deepcopy(SAMPLE_CLUSTER_DICT)
        cluster_dict['management_private_key'] = 'abacaba'
        cluster_dict['node_groups'][0]['id'] = 'some_id'

        cluster = r.ClusterResource(cluster_dict)
        self.assertEqual(cluster.to_dict(), SAMPLE_CLUSTER_DICT)
Exemple #4
0
    def test_attach(self, add_step, add_event,
                    p_create_attach_vol, p_await, p_mount):
        p_create_attach_vol.side_effect = ['/dev/vdb', '/dev/vdc'] * 2
        p_await.return_value = None
        p_mount.return_value = None
        add_event.return_value = None
        add_step.return_value = None

        instance1 = {'id': '1',
                     'instance_id': '123',
                     'instance_name': 'inst_1'}

        instance2 = {'id': '2',
                     'instance_id': '456',
                     'instance_name': 'inst_2'}

        ng = {'volumes_per_node': 2,
              'volumes_size': 2,
              'volumes_availability_zone': None,
              'volume_mount_prefix': '/mnt/vols',
              'volume_type': None,
              'name': 'master',
              'cluster_id': '11',
              'instances': [instance1, instance2],
              'volume_local_to_instance': False}

        cluster = r.ClusterResource({'node_groups': [ng]})

        volumes.attach_to_instances(g.get_instances(cluster))
        self.assertEqual(4, p_create_attach_vol.call_count)
        self.assertEqual(2, p_await.call_count)
        self.assertEqual(4, p_mount.call_count)
Exemple #5
0
def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
    dct = {'id': six.text_type(uuid.uuid4()), 'name': name,
           'tenant_id': tenant, 'plugin_name': plugin,
           'hadoop_version': version, 'node_groups': node_groups,
           'cluster_configs': {}, "sahara_info": {}, 'is_protected': False}
    dct.update(kwargs)
    return r.ClusterResource(dct)
Exemple #6
0
def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
    dct = {
        'name': name,
        'tenant_id': tenant,
        'plugin_name': plugin,
        'hadoop_version': version,
        'node_groups': node_groups
    }
    dct.update(kwargs)
    return r.ClusterResource(dct)
Exemple #7
0
    def test_cluster_resource(self):
        cluster = r.ClusterResource(SAMPLE_CLUSTER_DICT)

        self.assertEqual(cluster.name, 'test-cluster')

        self.assertEqual(cluster.node_groups[0].name, 'master')
        self.assertIsInstance(cluster.node_groups[0], r.NodeGroupResource)
        self.assertEqual(cluster.node_groups[0].cluster.name, 'test-cluster')

        self.assertEqual(cluster.node_groups[1].instances[0].name,
                         'test-cluster-001')
        self.assertIsInstance(cluster.node_groups[1].instances[0],
                              r.InstanceResource)
        self.assertEqual(cluster.node_groups[1].instances[0].node_group.name,
                         'worker')
Exemple #8
0
def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
    dct = {
        'id': uuidutils.generate_uuid(),
        'name': name,
        'tenant_id': tenant,
        'plugin_name': plugin,
        'hadoop_version': version,
        'node_groups': node_groups,
        'cluster_configs': {},
        "sahara_info": {},
        'user_keypair_id': None,
        'default_image_id': None,
        'is_protected': False
    }
    dct.update(kwargs)
    return r.ClusterResource(dct)
Exemple #9
0
def create_fake_cluster(cluster, existing, additional):
    counts = existing.copy()
    counts.update(additional)

    def update_ng(node_group):
        ng_dict = node_group.to_dict()
        count = counts[node_group.id]
        ng_dict.update(dict(count=count))
        return r.NodeGroupResource(ng_dict)

    def need_upd(node_group):
        return node_group.id in counts and counts[node_group.id] > 0

    updated = map(update_ng, filter(need_upd, cluster.node_groups))
    not_updated = filter(lambda ng: not need_upd(ng) and ng is not None,
                         cluster.node_groups)
    cluster_dict = cluster.to_dict()
    cluster_dict.update({'node_groups': updated + not_updated})
    fake = r.ClusterResource(cluster_dict)
    return fake
Exemple #10
0
    def test_attach(self, p_dev_path, p_create_attach_vol, p_await, p_mount):
        p_dev_path.return_value = ['123', '456']
        p_create_attach_vol.return_value = None
        p_await.return_value = None
        p_mount.return_value = None

        instance1 = {'instance_id': '123', 'instance_name': 'inst_1'}
        instance2 = {'instance_id': '456', 'instance_name': 'inst_2'}

        ng = {
            'volumes_per_node': 2,
            'volumes_size': 2,
            'volume_mount_prefix': '/mnt/vols',
            'name': 'master',
            'instances': [instance1, instance2]
        }

        cluster = r.ClusterResource({'node_groups': [ng]})

        volumes.attach(cluster)
        self.assertEqual(p_create_attach_vol.call_count, 4)
        self.assertEqual(p_await.call_count, 2)
        self.assertEqual(p_mount.call_count, 4)
        self.assertEqual(p_dev_path.call_count, 2)
Exemple #11
0
 def test_to_wrapped_dict(self):
     cluster = r.ClusterResource(SAMPLE_CLUSTER_DICT)
     wrapped_dict = cluster.to_wrapped_dict()
     self.assertEqual(len(wrapped_dict), 1)
     self.assertEqual(wrapped_dict['cluster'], SAMPLE_CLUSTER_DICT)
Exemple #12
0
 def test_to_dict(self):
     cluster = r.ClusterResource(SAMPLE_CLUSTER_DICT)
     self.assertEqual(cluster.to_dict(), SAMPLE_CLUSTER_DICT)
Exemple #13
0
def create_cluster_resource(data, **kwargs):
    return resource.ClusterResource(data)