Exemplo n.º 1
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug('bay_heat bay_create')

        osc = clients.OpenStackClients(context)

        bay.uuid = uuid.uuid4()
        try:
            # Create trustee/trust and set them to bay
            trust_manager.create_trustee_and_trust(osc, bay)
            # Generate certificate and set the cert reference to bay
            cert_manager.generate_certificates_to_bay(bay, context=context)
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_CREATE, taxonomy.OUTCOME_PENDING)
            created_stack = _create_stack(context, osc, bay,
                                          bay_create_timeout)
        except Exception as e:
            cert_manager.delete_certificates_from_bay(bay, context=context)
            trust_manager.delete_trustee_and_trust(osc, context, bay)
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_CREATE, taxonomy.OUTCOME_FAILURE)

            if isinstance(e, exc.HTTPBadRequest):
                e = exception.InvalidParameterValue(message=six.text_type(e))

                raise e
            raise

        bay.stack_id = created_stack['stack']['id']
        bay.status = bay_status.CREATE_IN_PROGRESS
        bay.create()

        self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 2
0
    def bay_delete(self, context, uuid):
        LOG.debug('bay_heat bay_delete')
        osc = clients.OpenStackClients(context)
        bay = objects.Bay.get_by_uuid(context, uuid)

        self._delete_trustee_and_trust(osc, bay)

        stack_id = bay.stack_id
        # NOTE(sdake): This will execute a stack_delete operation.  This will
        # Ignore HTTPNotFound exceptions (stack wasn't present).  In the case
        # that Heat couldn't find the stack representing the bay, likely a user
        # has deleted the stack outside the context of Magnum.  Therefore the
        # contents of the bay are forever lost.
        #
        # If the exception is unhandled, the original exception will be raised.
        try:
            osc.heat().stacks.delete(stack_id)
        except exc.HTTPNotFound:
            LOG.info(_LI('The stack %s was not be found during bay'
                         ' deletion.'), stack_id)
            try:
                cert_manager.delete_certificates_from_bay(bay)
                bay.destroy()
            except exception.BayNotFound:
                LOG.info(_LI('The bay %s has been deleted by others.'), uuid)
            return None
        except Exception:
            raise

        self._poll_and_check(osc, bay)

        return None
Exemplo n.º 3
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug('bay_heat bay_create')

        osc = clients.OpenStackClients(context)

        bay.uuid = uuid.uuid4()
        self._create_trustee_and_trust(osc, bay)
        try:
            # Generate certificate and set the cert reference to bay
            cert_manager.generate_certificates_to_bay(bay)
            created_stack = _create_stack(context, osc, bay,
                                          bay_create_timeout)
        except exc.HTTPBadRequest as e:
            cert_manager.delete_certificates_from_bay(bay)
            raise exception.InvalidParameterValue(message=six.text_type(e))
        except Exception:
            raise

        bay.stack_id = created_stack['stack']['id']
        bay.status = bay_status.CREATE_IN_PROGRESS
        bay.create()

        self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 4
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug('bay_heat bay_create')

        osc = clients.OpenStackClients(context)

        bay.uuid = uuid.uuid4()
        try:
            # Create trustee/trust and set them to bay
            trust_manager.create_trustee_and_trust(osc, bay)
            # Generate certificate and set the cert reference to bay
            cert_manager.generate_certificates_to_bay(bay, context=context)
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_CREATE, taxonomy.OUTCOME_PENDING)
            created_stack = _create_stack(context, osc, bay,
                                          bay_create_timeout)
        except Exception as e:
            cert_manager.delete_certificates_from_bay(bay, context=context)
            trust_manager.delete_trustee_and_trust(osc, context, bay)
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_CREATE, taxonomy.OUTCOME_FAILURE)

            if isinstance(e, exc.HTTPBadRequest):
                e = exception.InvalidParameterValue(message=six.text_type(e))

            raise e

        bay.stack_id = created_stack['stack']['id']
        bay.status = bay_status.CREATE_IN_PROGRESS
        bay.create()

        self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 5
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug('bay_heat bay_create')

        osc = clients.OpenStackClients(context)

        try:
            # Use Senlin to Create a Cluster
            params = {
                'master_profile_name': 'SUR_HEAT_Master_Profile',
                'minion_profile_name': 'SUR_HEAT_Minion_Profile',
                'master_profile_spec': '/opt/stack/magnum/magnum/sur/SURspec/heat-fedora/master.yaml',
                'minion_profile_spec': '/opt/stack/magnum/magnum/sur/SURspec/heat-fedora/minion.yaml',
                'si_policy_spec' : '/opt/stack/magnum/magnum/sur/SURspec/scaling_policy.spec',
                'so_policy_spec' : '/opt/stack/magnum/magnum/sur/SURspec/scaling_policy.spec',
                'cluster_name': 'SUR_HEAT_Cluster',
	        'node_count': 2
            }
            senlinfunc.create_cluster(osc, **params)
            # Generate certificate and set the cert reference to bay
            cert_manager.generate_certificates_to_bay(bay)
            #created_stack = _create_senlin_stack(context, osc, bay,
            #                                     bay_create_timeout)
        except exc.HTTPBadRequest as e:
            cert_manager.delete_certificates_from_bay(bay)
            raise exception.InvalidParameterValue(message=str(e))
        except Exception:
            raise

        #bay.stack_id = created_stack['stack']['id']
        bay.stack_id = 'SUR_cluster'
        bay.create()

        #self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 6
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug('bay_heat bay_create')

        osc = clients.OpenStackClients(context)

        baymodel = objects.BayModel.get_by_uuid(context,
                                                bay.baymodel_id)
        if baymodel.registry_enabled:
            trust = osc.keystone().create_trust(
                CONF.docker_registry.trustee_user_id,
                CONF.docker_registry.trust_roles)
            bay.registry_trust_id = trust.id

        try:
            # Generate certificate and set the cert reference to bay
            bay.uuid = uuid.uuid4()
            cert_manager.generate_certificates_to_bay(bay)
            created_stack = _create_stack(context, osc, bay,
                                          bay_create_timeout)
        except exc.HTTPBadRequest as e:
            cert_manager.delete_certificates_from_bay(bay)
            raise exception.InvalidParameterValue(message=six.text_type(e))
        except Exception:
            raise

        bay.stack_id = created_stack['stack']['id']
        bay.create()

        self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 7
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug('bay_heat bay_create')

        osc = clients.OpenStackClients(context)

        baymodel = objects.BayModel.get_by_uuid(context,
                                                bay.baymodel_id)
        if baymodel.registry_enabled:
            trust = osc.keystone().create_trust(
                CONF.docker_registry.trustee_user_id,
                CONF.docker_registry.trust_roles)
            bay.registry_trust_id = trust.id

        try:
            # Generate certificate and set the cert reference to bay
            bay.uuid = uuid.uuid4()
            cert_manager.generate_certificates_to_bay(bay)
            created_stack = _create_stack(context, osc, bay,
                                          bay_create_timeout)
        except exc.HTTPBadRequest as e:
            cert_manager.delete_certificates_from_bay(bay)
            raise exception.InvalidParameterValue(message=six.text_type(e))
        except Exception:
            raise

        bay.stack_id = created_stack['stack']['id']
        bay.create()

        self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 8
0
    def bay_delete(self, context, uuid):
        LOG.debug('bay_heat bay_delete')
        osc = clients.OpenStackClients(context)
        bay = objects.Bay.get_by_uuid(context, uuid)
        stack_id = bay.stack_id
        # NOTE(sdake): This will execute a stack_delete operation.  This will
        # Ignore HTTPNotFound exceptions (stack wasn't present).  In the case
        # that Heat couldn't find the stack representing the bay, likely a user
        # has deleted the stack outside the context of Magnum.  Therefore the
        # contents of the bay are forever lost.
        #
        # If the exception is unhandled, the original exception will be raised.
        try:
            osc.heat().stacks.delete(stack_id)
        except exc.HTTPNotFound:
            LOG.info(
                _LI('The stack %s was not be found during bay'
                    ' deletion.') % stack_id)
            try:
                cert_manager.delete_certificates_from_bay(bay)
                bay.destroy()
            except exception.BayNotFound:
                LOG.info(_LI('The bay %s has been deleted by others.') % uuid)
            return None
        except Exception:
            raise

        self._poll_and_check(osc, bay)

        return None
Exemplo n.º 9
0
    def test_delete_certtificate_without_cert_ref(self):
        mock_delete_cert = self.CertManager.delete_cert
        mock_bay = mock.MagicMock()
        mock_bay.ca_cert_ref = None
        mock_bay.magnum_cert_ref = None

        cert_manager.delete_certificates_from_bay(mock_bay)
        self.assertFalse(mock_delete_cert.called)
Exemplo n.º 10
0
 def _delete_complete(self):
     LOG.info(_LI('Bay has been deleted, stack_id: %s') % self.bay.stack_id)
     try:
         cert_manager.delete_certificates_from_bay(self.bay)
         self.bay.destroy()
     except exception.BayNotFound:
         LOG.info(
             _LI('The bay %s has been deleted by others.') % self.bay.uuid)
Exemplo n.º 11
0
 def _delete_complete(self):
     LOG.info(_LI('Bay has been deleted, stack_id: %s')
              % self.bay.stack_id)
     try:
         cert_manager.delete_certificates_from_bay(self.bay)
         self.bay.destroy()
     except exception.BayNotFound:
         LOG.info(_LI('The bay %s has been deleted by others.')
                  % self.bay.uuid)
Exemplo n.º 12
0
 def _delete_complete(self):
     LOG.info(_LI('Bay has been deleted, stack_id: %s') % self.bay.stack_id)
     try:
         trust_manager.delete_trustee_and_trust(self.openstack_client,
                                                self.context, self.bay)
         cert_manager.delete_certificates_from_bay(self.bay)
         self.bay.destroy()
     except exception.BayNotFound:
         LOG.info(
             _LI('The bay %s has been deleted by others.') % self.bay.uuid)
Exemplo n.º 13
0
    def test_delete_certtificate(self):
        mock_delete_cert = self.CertManager.delete_cert
        expected_cert_ref = 'cert_ref'
        expected_ca_cert_ref = 'ca_cert_ref'
        mock_bay = mock.MagicMock()
        mock_bay.ca_cert_ref = expected_ca_cert_ref
        mock_bay.magnum_cert_ref = expected_cert_ref

        cert_manager.delete_certificates_from_bay(mock_bay)
        mock_delete_cert.assert_any_call(expected_ca_cert_ref)
        mock_delete_cert.assert_any_call(expected_cert_ref)
Exemplo n.º 14
0
 def _delete_complete(self):
     LOG.info(_LI('Bay has been deleted, stack_id: %s')
              % self.bay.stack_id)
     try:
         trust_manager.delete_trustee_and_trust(self.openstack_client,
                                                self.context,
                                                self.bay)
         cert_manager.delete_certificates_from_bay(self.bay)
         self.bay.destroy()
     except exception.BayNotFound:
         LOG.info(_LI('The bay %s has been deleted by others.')
                  % self.bay.uuid)
Exemplo n.º 15
0
    def test_delete_certtificate_if_raise_error(self):
        mock_delete_cert = self.CertManager.delete_cert
        expected_cert_ref = 'cert_ref'
        expected_ca_cert_ref = 'ca_cert_ref'
        mock_bay = mock.MagicMock()
        mock_bay.ca_cert_ref = expected_ca_cert_ref
        mock_bay.magnum_cert_ref = expected_cert_ref

        mock_delete_cert.side_effect = ValueError

        cert_manager.delete_certificates_from_bay(mock_bay)
        mock_delete_cert.assert_any_call(expected_ca_cert_ref)
        mock_delete_cert.assert_any_call(expected_cert_ref)
Exemplo n.º 16
0
    def test_delete_certtificate(self):
        mock_delete_cert = self.CertManager.delete_cert
        expected_cert_ref = 'cert_ref'
        expected_ca_cert_ref = 'ca_cert_ref'
        mock_bay = mock.MagicMock()
        mock_bay.uuid = "mock_bay_uuid"
        mock_bay.ca_cert_ref = expected_ca_cert_ref
        mock_bay.magnum_cert_ref = expected_cert_ref

        cert_manager.delete_certificates_from_bay(mock_bay)
        mock_delete_cert.assert_any_call(expected_ca_cert_ref,
                                         resource_ref=mock_bay.uuid,
                                         context=None)
        mock_delete_cert.assert_any_call(expected_cert_ref,
                                         resource_ref=mock_bay.uuid,
                                         context=None)
Exemplo n.º 17
0
    def bay_delete(self, context, uuid):
        LOG.debug('bay_heat bay_delete')
        osc = clients.OpenStackClients(context)
        bay = objects.Bay.get_by_uuid(context, uuid)

        stack_id = bay.stack_id
        # NOTE(sdake): This will execute a stack_delete operation.  This will
        # Ignore HTTPNotFound exceptions (stack wasn't present).  In the case
        # that Heat couldn't find the stack representing the bay, likely a user
        # has deleted the stack outside the context of Magnum.  Therefore the
        # contents of the bay are forever lost.
        #
        # If the exception is unhandled, the original exception will be raised.
        try:
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_DELETE, taxonomy.OUTCOME_PENDING)
            osc.heat().stacks.delete(stack_id)
        except exc.HTTPNotFound:
            LOG.info(_LI('The stack %s was not found during bay'
                         ' deletion.'), stack_id)
            try:
                trust_manager.delete_trustee_and_trust(osc, context, bay)
                cert_manager.delete_certificates_from_bay(bay, context=context)
                bay.destroy()
            except exception.ClusterNotFound:
                LOG.info(_LI('The bay %s has been deleted by others.'), uuid)
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_DELETE, taxonomy.OUTCOME_SUCCESS)
            return None
        except exc.HTTPConflict:
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_DELETE, taxonomy.OUTCOME_FAILURE)
            raise exception.OperationInProgress(bay_name=bay.name)
        except Exception:
            conductor_utils.notify_about_bay_operation(
                context, taxonomy.ACTION_DELETE, taxonomy.OUTCOME_FAILURE)
            raise

        bay.status = bay_status.DELETE_IN_PROGRESS

        self._poll_and_check(osc, bay)

        return None
Exemplo n.º 18
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug('bay_heat bay_create')

        osc = clients.OpenStackClients(context)

        try:
            # Generate certificate and set the cert reference to bay
            cert_manager.generate_certificates_to_bay(bay)
            created_stack = _create_stack(context, osc, bay,
                                          bay_create_timeout)
        except exc.HTTPBadRequest as e:
            cert_manager.delete_certificates_from_bay(bay)
            raise exception.InvalidParameterValue(message=str(e))
        except Exception:
            raise

        bay.stack_id = created_stack['stack']['id']
        bay.create()

        self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 19
0
    def bay_create(self, context, bay, bay_create_timeout):
        LOG.debug("bay_heat bay_create")

        osc = clients.OpenStackClients(context)

        try:
            # Generate certificate and set the cert reference to bay
            cert_manager.generate_certificates_to_bay(bay)
            # bay.stack_id = 'SUR_cluster'
            bay.create()
            # Use Senlin to Create a Cluster
            params = {
                "master_profile_name": "SUR_Master_Profile",
                "minion_profile_name": "SUR_Minion_Profile",
                "master_profile_spec": "/opt/stack/magnum/magnum/sur/SURspec/heat-fedora/master.yaml",
                "minion_profile_spec": "/opt/stack/magnum/magnum/sur/SURspec/heat-fedora/minion.yaml",
                "minion_template_spec": "/opt/stack/magnum/magnum/sur/SURspec/heat-fedora/heat-kubernetes-split/kubeminion.yaml",
                "si_policy_spec": "/opt/stack/magnum/magnum/sur/SURspec/scaling_in_policy.yaml",
                "so_policy_spec": "/opt/stack/magnum/magnum/sur/SURspec/scaling_out_policy.yaml",
                "cluster_name": "SUR_Cluster",
                "node_count": 2,
            }
            senlinfunc.create_cluster(osc, bay, **params)
            # created_stack = _create_senlin_stack(context, osc, bay,
            #                                     bay_create_timeout)
        except exc.HTTPBadRequest as e:
            cert_manager.delete_certificates_from_bay(bay)
            raise exception.InvalidParameterValue(message=str(e))
        except Exception:
            raise

        # bay.stack_id = created_stack['stack']['id']
        # bay.create()

        # self._poll_and_check(osc, bay)

        return bay
Exemplo n.º 20
0
    def poll_and_check(self):
        # TODO(yuanying): temporary implementation to update api_address,
        # node_addresses and bay status
        stack = self.openstack_client.heat().stacks.get(self.bay.stack_id)
        self.attempts += 1
        # poll_and_check is detached and polling long time to check status,
        # so another user/client can call delete bay/stack.
        if stack.stack_status == bay_status.DELETE_COMPLETE:
            LOG.info(_LI('Bay has been deleted, stack_id: %s')
                     % self.bay.stack_id)
            try:
                cert_manager.delete_certificates_from_bay(self.bay)
                self.bay.destroy()
            except exception.BayNotFound:
                LOG.info(_LI('The bay %s has been deleted by others.')
                         % self.bay.uuid)
            raise loopingcall.LoopingCallDone()
        if (stack.stack_status in [bay_status.CREATE_COMPLETE,
                                   bay_status.UPDATE_COMPLETE]):
            self.template_def.update_outputs(stack, self.bay)

            self.bay.status = stack.stack_status
            self.bay.status_reason = stack.stack_status_reason
            stack_nc_param = self.template_def.get_heat_param(
                bay_attr='node_count')
            self.bay.node_count = stack.parameters[stack_nc_param]
            self.bay.save()
            raise loopingcall.LoopingCallDone()
        elif stack.stack_status != self.bay.status:
            self.bay.status = stack.stack_status
            self.bay.status_reason = stack.stack_status_reason
            stack_nc_param = self.template_def.get_heat_param(
                bay_attr='node_count')
            self.bay.node_count = stack.parameters[stack_nc_param]
            self.bay.save()
        if stack.stack_status == bay_status.CREATE_FAILED:
            LOG.error(_LE('Unable to create bay, stack_id: %(stack_id)s, '
                          'reason: %(reason)s') %
                      {'stack_id': self.bay.stack_id,
                       'reason': stack.stack_status_reason})
            raise loopingcall.LoopingCallDone()
        if stack.stack_status == bay_status.DELETE_FAILED:
            LOG.error(_LE('Unable to delete bay, stack_id: %(stack_id)s, '
                          'reason: %(reason)s') %
                      {'stack_id': self.bay.stack_id,
                       'reason': stack.stack_status_reason})
            raise loopingcall.LoopingCallDone()
        if stack.stack_status == bay_status.UPDATE_FAILED:
            LOG.error(_LE('Unable to update bay, stack_id: %(stack_id)s, '
                          'reason: %(reason)s') %
                      {'stack_id': self.bay.stack_id,
                       'reason': stack.stack_status_reason})
            raise loopingcall.LoopingCallDone()
        # only check max attempts when the stack is being created when
        # the timeout hasn't been set. If the timeout has been set then
        # the loop will end when the stack completes or the timeout occurs
        if stack.stack_status == bay_status.CREATE_IN_PROGRESS:
            if (stack.timeout_mins is None and
               self.attempts > cfg.CONF.bay_heat.max_attempts):
                LOG.error(_LE('Bay check exit after %(attempts)s attempts,'
                              'stack_id: %(id)s, stack_status: %(status)s') %
                          {'attempts': cfg.CONF.bay_heat.max_attempts,
                           'id': self.bay.stack_id,
                           'status': stack.stack_status})
                raise loopingcall.LoopingCallDone()
        else:
            if self.attempts > cfg.CONF.bay_heat.max_attempts:
                LOG.error(_LE('Bay check exit after %(attempts)s attempts,'
                              'stack_id: %(id)s, stack_status: %(status)s') %
                          {'attempts': cfg.CONF.bay_heat.max_attempts,
                           'id': self.bay.stack_id,
                           'status': stack.stack_status})
                raise loopingcall.LoopingCallDone()