Ejemplo n.º 1
0
 def test_create_multiple_clusters_success(self, check_cluster):
     MULTIPLE_CLUSTERS = SAMPLE_CLUSTER.copy()
     MULTIPLE_CLUSTERS['count'] = 2
     clusters = api.create_multiple_clusters(MULTIPLE_CLUSTERS)
     self.assertEqual(2, check_cluster.call_count)
     result_cluster1 = api.get_cluster(clusters['clusters'][0])
     result_cluster2 = api.get_cluster(clusters['clusters'][1])
     self.assertEqual(c_u.CLUSTER_STATUS_ACTIVE, result_cluster1.status)
     self.assertEqual(c_u.CLUSTER_STATUS_ACTIVE, result_cluster2.status)
     expected_count = {
         'ng_1': 1,
         'ng_2': 3,
         'ng_3': 1,
     }
     ng_count = 0
     for ng in result_cluster1.node_groups:
         self.assertEqual(expected_count[ng.name], ng.count)
         ng_count += 1
     self.assertEqual(3, ng_count)
     api.terminate_cluster(result_cluster1.id)
     api.terminate_cluster(result_cluster2.id)
     self.assertEqual(
         ['get_open_ports', 'recommend_configs', 'validate',
          'ops.provision_cluster',
          'get_open_ports', 'recommend_configs', 'validate',
          'ops.provision_cluster',
          'ops.terminate_cluster',
          'ops.terminate_cluster'], self.calls_order)
Ejemplo n.º 2
0
def clusters_delete(cluster_id, **kwargs):
    all_tenants = kwargs.get('all_tenants', None)
    if all_tenants: 
        ctx = context.ctx()
        ctx.check_admin()
    api.terminate_cluster(cluster_id)
    return u.render()
Ejemplo n.º 3
0
    def terminate_unneeded_clusters(self, ctx):
        LOG.debug('Terminating unneeded clusters')
        ctx = context.get_admin_context()
        context.set_ctx(ctx)
        for cluster in conductor.cluster_get_all(ctx, status='Active'):
            if not cluster.is_transient:
                continue

            jc = conductor.job_execution_count(ctx,
                                               end_time=None,
                                               cluster_id=cluster.id)

            if jc > 0:
                continue

            cluster_updated_at = timeutils.normalize_time(
                timeutils.parse_isotime(cluster.updated_at))
            current_time = timeutils.utcnow()
            spacing = timeutils.delta_seconds(cluster_updated_at, current_time)
            if spacing < CONF.min_transient_cluster_active_time:
                continue

            if CONF.use_identity_api_v3:
                trusts.use_os_admin_auth_token(cluster)
                api.terminate_cluster(cluster.id)
                LOG.debug('Terminated cluster %s with id %s' %
                          (cluster.name, cluster.id))
            else:
                if cluster.status != 'AwaitingTermination':
                    conductor.cluster_update(
                        ctx,
                        cluster,
                        {'status': 'AwaitingTermination'})
        context.set_ctx(None)
Ejemplo n.º 4
0
 def test_create_multiple_clusters_success(self, check_cluster):
     MULTIPLE_CLUSTERS = SAMPLE_CLUSTER.copy()
     MULTIPLE_CLUSTERS['count'] = 2
     clusters = api.create_multiple_clusters(MULTIPLE_CLUSTERS)
     self.assertEqual(2, check_cluster.call_count)
     result_cluster1 = api.get_cluster(clusters['clusters'][0])
     result_cluster2 = api.get_cluster(clusters['clusters'][1])
     self.assertEqual('Active', result_cluster1.status)
     self.assertEqual('Active', result_cluster2.status)
     expected_count = {
         'ng_1': 1,
         'ng_2': 3,
         'ng_3': 1,
     }
     ng_count = 0
     for ng in result_cluster1.node_groups:
         self.assertEqual(expected_count[ng.name], ng.count)
         ng_count += 1
     self.assertEqual(3, ng_count)
     api.terminate_cluster(result_cluster1.id)
     api.terminate_cluster(result_cluster2.id)
     self.assertEqual(
         ['get_open_ports', 'recommend_configs', 'validate',
          'ops.provision_cluster',
          'get_open_ports', 'recommend_configs', 'validate',
          'ops.provision_cluster',
          'ops.terminate_cluster',
          'ops.terminate_cluster'], self.calls_order)
Ejemplo n.º 5
0
def clusters_delete(cluster_id, **kwargs):
    all_tenants = kwargs.get('all_tenants', None)
    if all_tenants:
        ctx = context.ctx()
        ctx.check_admin()
    api.terminate_cluster(cluster_id)
    return u.render()
Ejemplo n.º 6
0
    def terminate_unneeded_clusters(self, ctx):
        LOG.debug('Terminating unneeded transient clusters')
        ctx = context.get_admin_context()
        context.set_ctx(ctx)
        for cluster in conductor.cluster_get_all(ctx, status='Active'):
            if not cluster.is_transient:
                continue

            jc = conductor.job_execution_count(ctx,
                                               end_time=None,
                                               cluster_id=cluster.id)

            if jc > 0:
                continue

            cluster_updated_at = timeutils.normalize_time(
                timeutils.parse_isotime(cluster.updated_at))
            current_time = timeutils.utcnow()
            spacing = timeutils.delta_seconds(cluster_updated_at, current_time)
            if spacing < CONF.min_transient_cluster_active_time:
                continue

            if CONF.use_identity_api_v3:
                trusts.use_os_admin_auth_token(cluster)

                LOG.info(_LI('Terminating transient cluster %(cluster)s '
                             'with id %(id)s'),
                         {'cluster': cluster.name, 'id': cluster.id})

                try:
                    api.terminate_cluster(cluster.id)
                except Exception as e:
                    LOG.info(_LI('Failed to terminate transient cluster '
                             '%(cluster)s with id %(id)s: %(error)s.'),
                             {'cluster': cluster.name,
                              'id': cluster.id,
                              'error': six.text_type(e)})

            else:
                if cluster.status != 'AwaitingTermination':
                    conductor.cluster_update(
                        ctx,
                        cluster,
                        {'status': 'AwaitingTermination'})
        context.set_ctx(None)
Ejemplo n.º 7
0
 def test_create_cluster_success(self, check_cluster):
     cluster = api.create_cluster(SAMPLE_CLUSTER)
     self.assertEqual(1, check_cluster.call_count)
     result_cluster = api.get_cluster(cluster.id)
     self.assertEqual('Active', result_cluster.status)
     expected_count = {
         'ng_1': 1,
         'ng_2': 3,
         'ng_3': 1,
     }
     ng_count = 0
     for ng in result_cluster.node_groups:
         self.assertEqual(expected_count[ng.name], ng.count)
         ng_count += 1
     self.assertEqual(3, ng_count)
     api.terminate_cluster(result_cluster.id)
     self.assertEqual(
         ['get_open_ports', 'recommend_configs', 'validate',
          'ops.provision_cluster',
          'ops.terminate_cluster'], self.calls_order)
Ejemplo n.º 8
0
 def test_create_cluster_success(self, check_cluster):
     cluster = api.create_cluster(SAMPLE_CLUSTER)
     self.assertEqual(1, check_cluster.call_count)
     result_cluster = api.get_cluster(cluster.id)
     self.assertEqual(c_u.CLUSTER_STATUS_ACTIVE, result_cluster.status)
     expected_count = {
         'ng_1': 1,
         'ng_2': 3,
         'ng_3': 1,
     }
     ng_count = 0
     for ng in result_cluster.node_groups:
         self.assertEqual(expected_count[ng.name], ng.count)
         ng_count += 1
     self.assertEqual(3, ng_count)
     api.terminate_cluster(result_cluster.id)
     self.assertEqual(
         ['get_open_ports', 'recommend_configs', 'validate',
          'ops.provision_cluster',
          'ops.terminate_cluster'], self.calls_order)
Ejemplo n.º 9
0
 def test_scale_cluster_success(self, check_scaling, check_cluster):
     cluster = api.create_cluster(SAMPLE_CLUSTER)
     api.scale_cluster(cluster.id, SCALE_DATA)
     result_cluster = api.get_cluster(cluster.id)
     self.assertEqual('Scaled', result_cluster.status)
     expected_count = {
         'ng_1': 3,
         'ng_2': 2,
         'ng_3': 1,
         'ng_4': 1,
     }
     ng_count = 0
     for ng in result_cluster.node_groups:
         self.assertEqual(expected_count[ng.name], ng.count)
         ng_count += 1
     self.assertEqual(4, ng_count)
     api.terminate_cluster(result_cluster.id)
     self.assertEqual(
         ['get_open_ports', 'validate', 'ops.provision_cluster',
          'get_open_ports', 'get_open_ports', 'validate_scaling',
          'ops.provision_scaled_cluster',
          'ops.terminate_cluster'], self.calls_order)
Ejemplo n.º 10
0
 def test_scale_cluster_success(self, check_scaling, check_cluster):
     cluster = api.create_cluster(SAMPLE_CLUSTER)
     api.scale_cluster(cluster.id, SCALE_DATA)
     result_cluster = api.get_cluster(cluster.id)
     self.assertEqual('Scaled', result_cluster.status)
     expected_count = {
         'ng_1': 3,
         'ng_2': 2,
         'ng_3': 1,
         'ng_4': 1,
     }
     ng_count = 0
     for ng in result_cluster.node_groups:
         self.assertEqual(expected_count[ng.name], ng.count)
         ng_count += 1
     self.assertEqual(4, ng_count)
     api.terminate_cluster(result_cluster.id)
     self.assertEqual(
         ['get_open_ports', 'recommend_configs', 'validate',
          'ops.provision_cluster', 'get_open_ports', 'get_open_ports',
          'recommend_configs', 'validate_scaling',
          'ops.provision_scaled_cluster',
          'ops.terminate_cluster'], self.calls_order)
Ejemplo n.º 11
0
def terminate_cluster(ctx, cluster, description):
    if CONF.use_identity_api_v3 and cluster.trust_id:
        trusts.use_os_admin_auth_token(cluster)
        context.set_current_cluster_id(cluster.id)

        LOG.debug('Terminating {description} cluster '
                  'in "{status}" state'.format(status=cluster.status,
                                               description=description))

        try:
            api.terminate_cluster(cluster.id)
        except Exception as e:
            LOG.warning(
                _LW('Failed to terminate {description} cluster in "{status}" '
                    'state: {error}.').format(error=six.text_type(e),
                                              status=cluster.status,
                                              description=description))

    else:
        if (cluster.status != c_u.CLUSTER_STATUS_AWAITINGTERMINATION):
            conductor.cluster_update(
                ctx, cluster,
                {'status': c_u.CLUSTER_STATUS_AWAITINGTERMINATION})
Ejemplo n.º 12
0
def terminate_cluster(ctx, cluster, description):
    if CONF.use_identity_api_v3 and cluster.trust_id:
        trusts.use_os_admin_auth_token(cluster)
        context.set_current_cluster_id(cluster.id)

        LOG.debug('Terminating {description} cluster '
                  'in "{status}" state'.format(status=cluster.status,
                                               description=description))

        try:
            api.terminate_cluster(cluster.id)
        except Exception as e:
            LOG.warning(_LW(
                'Failed to terminate {description} cluster in "{status}" '
                'state: {error}.').format(error=six.text_type(e),
                                          status=cluster.status,
                                          description=description))

    else:
        if (cluster.status !=
                c_u.CLUSTER_STATUS_AWAITINGTERMINATION):
            conductor.cluster_update(
                ctx, cluster,
                {'status': c_u.CLUSTER_STATUS_AWAITINGTERMINATION})
Ejemplo n.º 13
0
def clusters_delete(cluster_id):
    api.terminate_cluster(cluster_id)
    return u.render()
Ejemplo n.º 14
0
def clusters_delete(cluster_id):
    api.terminate_cluster(cluster_id)
    return u.render()