def check_stack_watches(self, sid):
        # Retrieve the stored credentials & create context
        # Require tenant_safe=False to the stack_get to defeat tenant
        # scoping otherwise we fail to retrieve the stack
        LOG.debug("Periodic watcher task for stack %s" % sid)
        admin_context = context.get_admin_context()
        db_stack = stack_object.Stack.get_by_id(admin_context, sid, tenant_safe=False, eager_load=True)
        if not db_stack:
            LOG.error(_LE("Unable to retrieve stack %s for periodic task"), sid)
            return
        stk = stack.Stack.load(admin_context, stack=db_stack, use_stored_context=True)

        # recurse into any nested stacks.
        children = stack_object.Stack.get_all_by_owner_id(admin_context, sid)
        for child in children:
            self.check_stack_watches(child.id)

        # Get all watchrules for this stack and evaluate them
        try:
            wrs = watch_rule_object.WatchRule.get_all_by_stack(admin_context, sid)
        except Exception as ex:
            LOG.warn(_LW("periodic_task db error watch rule removed? %(ex)s"), ex)
            return

        def run_alarm_action(stk, actions, details):
            for action in actions:
                action(details=details)
            for res in six.itervalues(stk):
                res.metadata_update()

        for wr in wrs:
            rule = watchrule.WatchRule.load(stk.context, watch=wr)
            actions = rule.evaluate()
            if actions:
                self.thread_group_mgr.start(sid, run_alarm_action, stk, actions, rule.get_details())
Esempio n. 2
0
 def _create_context(self, user='******'):
     ctx = context.get_admin_context()
     self.m.StubOutWithMock(ctx, 'username')
     ctx.username = user
     self.m.StubOutWithMock(ctx, 'tenant_id')
     ctx.tenant_id = 't'
     return ctx
Esempio n. 3
0
    def _periodic_watcher_task(self, sid):
        """
        Periodic task, created for each stack, triggers watch-rule
        evaluation for all rules defined for the stack
        sid = stack ID
        """
        # Retrieve the stored credentials & create context
        # Require admin=True to the stack_get to defeat tenant
        # scoping otherwise we fail to retrieve the stack
        logger.debug("Periodic watcher task for stack %s" % sid)
        admin_context = context.get_admin_context()
        stack = db_api.stack_get(admin_context, sid, admin=True)
        if not stack:
            logger.error("Unable to retrieve stack %s for periodic task" %
                         sid)
            return
        user_creds = db_api.user_creds_get(stack.user_creds_id)
        stack_context = context.RequestContext.from_dict(user_creds)

        # Get all watchrules for this stack and evaluate them
        try:
            wrs = db_api.watch_rule_get_all_by_stack(stack_context, sid)
        except Exception as ex:
            logger.warn('periodic_task db error (%s) %s' %
                        ('watch rule removed?', str(ex)))
            return
        for wr in wrs:
            rule = watchrule.WatchRule.load(stack_context, watch=wr)
            actions = rule.evaluate()
            for action in actions:
                self._start_in_thread(sid, action)
Esempio n. 4
0
def create_context(mocks, user="******", tenant="test_admin", ctx=None):
    ctx = ctx or context.get_admin_context()
    mocks.StubOutWithMock(ctx, "username")
    mocks.StubOutWithMock(ctx, "tenant_id")
    ctx.username = user
    ctx.tenant_id = tenant
    return ctx
Esempio n. 5
0
    def create_stack(self, stack_name='test_stack',
                     template=test_template_waitcondition, params={},
                     stub=True):
        temp = template_format.parse(template)
        template = parser.Template(temp)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx, stack_name, template,
                             environment.Environment(params),
                             disable_rollback=True)

        # Stub out the stack ID so we have a known value
        with UUIDStub(self.stack_id):
            stack.store()

        if stub:
            self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
            wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(
                self.fc)

            id = identifier.ResourceIdentifier('test_tenant', stack.name,
                                               stack.id, '', 'WaitHandle')
            self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
            wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        return stack
Esempio n. 6
0
    def setUp(self):
        super(EventTest, self).setUp()
        self.username = '******'

        setup_dummy_db()
        self.ctx = context.get_admin_context()
        self.m.StubOutWithMock(self.ctx, 'username')
        self.ctx.username = self.username

        self.m.ReplayAll()

        # patch in a dummy property schema for GenericResource
        dummy_schema = {'foo': {'Type': 'Boolean', 'Required': True}}
        generic_rsrc.GenericResource.properties_schema = dummy_schema

        resource._register_class('GenericResourceType',
                                 generic_rsrc.GenericResource)

        self.stack = parser.Stack(self.ctx, 'event_load_test_stack',
                                  template.Template(tmpl))
        self.stack.store()

        self.resource = self.stack['EventTestResource']
        self.resource._store()
        self.addCleanup(db_api.stack_delete, self.ctx, self.stack.id)
Esempio n. 7
0
    def create_stack(self,
                     stack_name='test_stack',
                     template=test_template_metadata,
                     params={},
                     stub=True):
        temp = template_format.parse(template)
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx,
                             stack_name,
                             template,
                             parameters,
                             disable_rollback=True)

        self.stack_id = stack.store()

        if stub:
            self.m.StubOutWithMock(instance.Instance, 'handle_create')
            self.m.StubOutWithMock(instance.Instance, 'check_active')
            instance.Instance.handle_create().AndReturn(None)
            instance.Instance.check_active(None).AndReturn(True)
            self.m.StubOutWithMock(instance.Instance, 'FnGetAtt')

        return stack
Esempio n. 8
0
    def start(self):
        vcs_string = version.version_string(type='long')
        LOG.info(_('Starting %(topic)s node (version %(vcs_string)s)'), {
            'topic': self.topic,
            'vcs_string': vcs_string
        })
        # TODO do we need this ? -> utils.cleanup_file_locks()
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        # self._create_service_ref(ctxt)

        self.conn = rpc.create_connection(new=True)
        LOG.debug(
            _("Creating Consumer connection for Service %s") % self.topic)

        rpc_dispatcher = self.manager.create_rpc_dispatcher()

        # Share this same connection for these Consumers
        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=False)

        node_topic = '%s.%s' % (self.topic, self.host)
        self.conn.create_consumer(node_topic, rpc_dispatcher, fanout=False)

        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=True)

        # Consume from all consumers in a thread
        self.conn.consume_in_thread()

        if self.periodic_interval:
            periodic = heat_utils.LoopingCall(self.periodic_tasks)
            periodic.start(interval=self.periodic_interval, now=False)
            self.timers.append(periodic)
Esempio n. 9
0
 def setUp(self):
     self.m = mox.Mox()
     self.ctx = context.get_admin_context()
     self.ctx.tenant_id = "test_tenant"
     self.fc = fakes.FakeKeystoneClient()
     self.man = service.EngineService("a-host", "a-topic")
     cfg.CONF.set_default("heat_waitcondition_server_url", "http://127.0.0.1:8000/v1/waitcondition")
Esempio n. 10
0
def main():
    import sys

    from heat.common import context
    from heat import version

    command_opt = cfg.SubCommandOpt('command',
                                    title='Commands',
                                    help='Show available commands',
                                    handler=add_command_parsers)
    CONF.register_cli_opt(command_opt)

    try:
        default_config_files = cfg.find_config_files('heat', 'heat-engine')
        CONF(sys.argv[1:],
             project='heat',
             prog='heat-recover',
             version=version.version_info.version_string(),
             default_config_files=default_config_files)
    except RuntimeError as e:
        sys.exit("ERROR: %s" % e)

    global ctxt
    ctxt = context.get_admin_context()

    CONF.command.func()
Esempio n. 11
0
    def setUp(self):
        super(EventTest, self).setUp()
        self.username = '******'

        setup_dummy_db()
        self.ctx = context.get_admin_context()
        self.m.StubOutWithMock(self.ctx, 'username')
        self.ctx.username = self.username

        self.m.ReplayAll()

        # patch in a dummy property schema for GenericResource
        dummy_schema = {'foo': {'Type': 'Boolean', 'Required': True}}
        generic_rsrc.GenericResource.properties_schema = dummy_schema

        resource._register_class('GenericResourceType',
                                 generic_rsrc.GenericResource)

        self.stack = parser.Stack(self.ctx, 'event_load_test_stack',
                                  template.Template(tmpl))
        self.stack.store()

        self.resource = self.stack['EventTestResource']
        self.resource._store()
        self.addCleanup(db_api.stack_delete, self.ctx, self.stack.id)
Esempio n. 12
0
    def create_stack(self, template=None):
        if template is None:
            template = alarm_template
        temp = template_format.parse(template)
        template = parser.Template(temp)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx, utils.random_name(), template,
                             disable_rollback=True)
        stack.store()

        self.m.StubOutWithMock(resource.Resource, 'keystone')
        resource.Resource.keystone().MultipleTimes().AndReturn(
            self.fc)

        self.m.StubOutWithMock(alarm.CeilometerAlarm, 'ceilometer')
        alarm.CeilometerAlarm.ceilometer().MultipleTimes().AndReturn(
            self.fa)

        al = copy.deepcopy(temp['Resources']['MEMAlarmHigh']['Properties'])
        al['description'] = mox.IgnoreArg()
        al['name'] = mox.IgnoreArg()
        al['alarm_actions'] = mox.IgnoreArg()
        self.m.StubOutWithMock(self.fa.alarms, 'create')
        self.fa.alarms.create(**al).AndReturn(FakeCeilometerAlarm())
        return stack
Esempio n. 13
0
    def create_stack(self, stack_name='test_stack2', params={}):
        temp = template_format.parse(test_template_waitcondition)
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        stack = parser.Stack(context.get_admin_context(), stack_name,
                             template, parameters)
        # Stub out the UUID for this test, so we can get an expected signature
        self.m.StubOutWithMock(uuid, 'uuid4')
        uuid.uuid4().AndReturn('STACKABCD1234')
        self.m.ReplayAll()
        stack.store()

        # Stub waitcondition status so all goes CREATE_COMPLETE
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'get_status')
        wc.WaitConditionHandle.get_status().AndReturn(['SUCCESS'])
        self.m.StubOutWithMock(wc.WaitCondition, '_create_timeout')
        wc.WaitCondition._create_timeout().AndReturn(eventlet.Timeout(5))

        # Stub keystone() with fake client
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
        wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fc)

        id = identifier.ResourceIdentifier('test_tenant', stack.name,
                                           stack.id, '', 'WaitHandle')
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
        wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        self.m.ReplayAll()
        stack.create()

        return stack
Esempio n. 14
0
 def service_clean(self):
     ctxt = context.get_admin_context()
     for service in service_objects.Service.get_all(ctxt):
         svc = service_utils.format_service(service)
         if svc['status'] == 'down':
             service_objects.Service.delete(ctxt, svc['id'])
     print(_('Dead engines are removed.'))
Esempio n. 15
0
 def setUp(self):
     super(validateTest, self).setUp()
     resources.initialise()
     self.fc = fakes.FakeClient()
     resources.initialise()
     setup_dummy_db()
     self.ctx = context.get_admin_context()
Esempio n. 16
0
    def _periodic_watcher_task(self, sid):
        """
        Periodic task, created for each stack, triggers watch-rule
        evaluation for all rules defined for the stack
        sid = stack ID
        """
        # Retrieve the stored credentials & create context
        # Require admin=True to the stack_get to defeat tenant
        # scoping otherwise we fail to retrieve the stack
        logger.debug("Periodic watcher task for stack %s" % sid)
        admin_context = context.get_admin_context()
        stack = db_api.stack_get(admin_context, sid, admin=True)
        if not stack:
            logger.error("Unable to retrieve stack %s for periodic task" % sid)
            return
        user_creds = db_api.user_creds_get(stack.user_creds_id)
        stack_context = context.RequestContext.from_dict(user_creds)

        # Get all watchrules for this stack and evaluate them
        try:
            wrs = db_api.watch_rule_get_all_by_stack(stack_context, sid)
        except Exception as ex:
            logger.warn('periodic_task db error (%s) %s' %
                        ('watch rule removed?', str(ex)))
            return
        for wr in wrs:
            rule = watchrule.WatchRule.load(stack_context, watch=wr)
            rule.evaluate()
Esempio n. 17
0
    def start(self):
        vcs_string = version.version_string_with_vcs()
        LOG.info(_('Starting %(topic)s node (version %(vcs_string)s)'),
                  {'topic': self.topic, 'vcs_string': vcs_string})
        # TODO do we need this ? -> utils.cleanup_file_locks()
        self.manager.init_host()
        self.model_disconnected = False
        ctxt = context.get_admin_context()
        # self._create_service_ref(ctxt)

        self.conn = rpc.create_connection(new=True)
        LOG.debug(_("Creating Consumer connection for Service %s") %
                  self.topic)

        rpc_dispatcher = self.manager.create_rpc_dispatcher()

        # Share this same connection for these Consumers
        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=False)

        node_topic = '%s.%s' % (self.topic, self.host)
        self.conn.create_consumer(node_topic, rpc_dispatcher, fanout=False)

        self.conn.create_consumer(self.topic, rpc_dispatcher, fanout=True)

        # Consume from all consumers in a thread
        self.conn.consume_in_thread()

        if self.periodic_interval:
            periodic = heat_utils.LoopingCall(self.periodic_tasks)
            periodic.start(interval=self.periodic_interval, now=False)
            self.timers.append(periodic)
Esempio n. 18
0
    def create_stack(self, stack_name='test_stack2', params={}):
        temp = template_format.parse(test_template_waitcondition)
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx,
                             stack_name,
                             template,
                             parameters,
                             disable_rollback=True)
        # Stub out the UUID for this test, so we can get an expected signature
        self.m.StubOutWithMock(uuid, 'uuid4')
        uuid.uuid4().AndReturn('STACKABCD1234')
        self.m.ReplayAll()
        stack.store()

        # Stub waitcondition status so all goes CREATE_COMPLETE
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'get_status')
        wc.WaitConditionHandle.get_status().AndReturn(['SUCCESS'])

        # Stub keystone() with fake client
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
        wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fc)

        id = identifier.ResourceIdentifier('test_tenant', stack.name, stack.id,
                                           '', 'WaitHandle')
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
        wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        self.m.ReplayAll()
        stack.create()

        return stack
Esempio n. 19
0
    def create_stack(self, stack_name='test_stack2', params={}):
        temp = template_format.parse(test_template_waitcondition)
        template = parser.Template(temp)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx, stack_name, template,
                             environment.Environment(params),
                             disable_rollback=True)
        # Stub out the UUID for this test, so we can get an expected signature
        with UUIDStub('STACKABCD1234'):
            stack.store()

        # Stub waitcondition status so all goes CREATE_COMPLETE
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'get_status')
        wc.WaitConditionHandle.get_status().AndReturn(['SUCCESS'])

        # Stub keystone() with fake client
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
        wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fc)

        id = identifier.ResourceIdentifier('test_tenant', stack.name,
                                           stack.id, '', 'WaitHandle')
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
        wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        self.m.ReplayAll()
        stack.create()

        return stack
Esempio n. 20
0
 def service_clean(self):
     ctxt = context.get_admin_context()
     for service in service_objects.Service.get_all(ctxt):
         svc = service_utils.format_service(service)
         if svc['status'] == 'down':
             service_objects.Service.delete(ctxt, svc['id'])
     print(_('Dead engines are removed.'))
Esempio n. 21
0
    def create_stack(self, template=None):
        if template is None:
            template = alarm_template
        temp = template_format.parse(template)
        template = parser.Template(temp)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx, utils.random_name(), template,
                             disable_rollback=True)
        stack.store()

        self.m.StubOutWithMock(resource.Resource, 'keystone')
        resource.Resource.keystone().MultipleTimes().AndReturn(
            self.fc)

        self.m.StubOutWithMock(alarm.CeilometerAlarm, 'ceilometer')
        alarm.CeilometerAlarm.ceilometer().MultipleTimes().AndReturn(
            self.fa)

        al = copy.deepcopy(temp['Resources']['MEMAlarmHigh']['Properties'])
        al['description'] = mox.IgnoreArg()
        al['name'] = mox.IgnoreArg()
        al['alarm_actions'] = mox.IgnoreArg()
        self.m.StubOutWithMock(self.fa.alarms, 'create')
        self.fa.alarms.create(**al).AndReturn(FakeCeilometerAlarm())
        return stack
Esempio n. 22
0
def create_context(mocks, user='******', tenant='test_tenant', ctx=None):
    ctx = ctx or context.get_admin_context()
    mocks.StubOutWithMock(ctx, 'username')
    mocks.StubOutWithMock(ctx, 'tenant_id')
    ctx.username = user
    ctx.tenant_id = tenant
    return ctx
Esempio n. 23
0
    def create_stack(self,
                     stack_name='test_stack',
                     template=test_template_waitcondition,
                     params={},
                     stub=True):
        temp = template_format.parse(template)
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx,
                             stack_name,
                             template,
                             parameters,
                             disable_rollback=True)

        self.stack_id = stack.store()

        if stub:
            self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
            wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(
                self.fc)

            id = identifier.ResourceIdentifier('test_tenant', stack.name,
                                               stack.id, '', 'WaitHandle')
            self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
            wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        return stack
Esempio n. 24
0
    def create_stack(self, stack_name='test_stack',
                     template=test_template_waitcondition, params={},
                     stub=True):
        temp = template_format.parse(template)
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx, stack_name, template, parameters,
                             disable_rollback=True)

        self.stack_id = stack.store()

        if stub:
            scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None)

            self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
            wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(
                self.fc)

            id = identifier.ResourceIdentifier('test_tenant', stack.name,
                                               stack.id, '', 'WaitHandle')
            self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
            wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        return stack
Esempio n. 25
0
    def create_stack(self, stack_name='test_stack2', params={}):
        temp = template_format.parse(test_template_waitcondition)
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        ctx = context.get_admin_context()
        ctx.tenant_id = 'test_tenant'
        stack = parser.Stack(ctx, stack_name, template, parameters,
                             disable_rollback=True)
        # Stub out the UUID for this test, so we can get an expected signature
        self.m.StubOutWithMock(uuid, 'uuid4')
        uuid.uuid4().AndReturn('STACKABCD1234')
        self.m.ReplayAll()
        stack.store()

        self.m.StubOutWithMock(scheduler.TaskRunner, '_sleep')
        scheduler.TaskRunner._sleep(mox.IsA(int)).AndReturn(None)

        # Stub waitcondition status so all goes CREATE_COMPLETE
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'get_status')
        wc.WaitConditionHandle.get_status().AndReturn(['SUCCESS'])

        # Stub keystone() with fake client
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'keystone')
        wc.WaitConditionHandle.keystone().MultipleTimes().AndReturn(self.fc)

        id = identifier.ResourceIdentifier('test_tenant', stack.name,
                                           stack.id, '', 'WaitHandle')
        self.m.StubOutWithMock(wc.WaitConditionHandle, 'identifier')
        wc.WaitConditionHandle.identifier().MultipleTimes().AndReturn(id)

        self.m.ReplayAll()
        stack.create()

        return stack
Esempio n. 26
0
 def _create_context(self, user='******'):
     ctx = context.get_admin_context()
     self.m.StubOutWithMock(ctx, 'username')
     ctx.username = user
     self.m.StubOutWithMock(ctx, 'tenant_id')
     ctx.tenant_id = self.tenant
     return ctx
Esempio n. 27
0
 def _create_context(self, user="******"):
     ctx = context.get_admin_context()
     self.m.StubOutWithMock(ctx, "username")
     ctx.username = user
     self.m.StubOutWithMock(ctx, "tenant_id")
     ctx.tenant_id = "t"
     return ctx
Esempio n. 28
0
    def create_stack(self, stack_name, temp, params):
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        stack = parser.Stack(context.get_admin_context(), stack_name, template,
                             parameters)

        stack.store()
        return stack
Esempio n. 29
0
 def setUp(self):
     self.m = mox.Mox()
     self.ctx = context.get_admin_context()
     self.ctx.tenant_id = 'test_tenant'
     self.fc = fakes.FakeKeystoneClient()
     self.man = service.EngineService('a-host', 'a-topic')
     cfg.CONF.set_default('heat_waitcondition_server_url',
                          'http://127.0.0.1:8000/v1/waitcondition')
Esempio n. 30
0
 def list_watch_data(self, req, watch_name):
     con = context.get_admin_context()
     data = self.engine_rpcapi.list_watch_data(con, watch_name=watch_name)
     if data:
         return data
     else:
         return json_error(404,
                           'The watch "%s" does not exist.' % watch_name)
Esempio n. 31
0
 def setUp(self):
     self.m = mox.Mox()
     self.ctx = context.get_admin_context()
     self.ctx.tenant_id = 'test_tenant'
     self.fc = fakes.FakeKeystoneClient()
     self.man = service.EngineService('a-host', 'a-topic')
     cfg.CONF.set_default('heat_waitcondition_server_url',
                          'http://127.0.0.1:8000/v1/waitcondition')
Esempio n. 32
0
 def create_watch_data(self, req, body, watch_name):
     con = context.get_admin_context()
     [error, watch_data] = self.engine_rpcapi.create_watch_data(con,
                                watch_name=watch_name,
                                stats_data=body)
     if error:
         return json_error(400, error)
     return json_response(201, watch_data)
Esempio n. 33
0
    def start(self):
        super(EngineService, self).start()

        # Create a periodic_watcher_task per-stack
        admin_context = context.get_admin_context()
        stacks = db_api.stack_get_all(admin_context, tenant_safe=False)
        for s in stacks:
            self.stack_watch.start_watch_task(s.id, admin_context)
Esempio n. 34
0
def do_resource_data_list():
    ctxt = context.get_admin_context()
    data = db_api.resource_data_get_all(ctxt, CONF.command.resource_id)

    print_format = "%-16s %-64s"

    for k in data.keys():
        print(print_format % (k, data[k]))
Esempio n. 35
0
def do_crypt_parameters_and_properties():
    """Encrypt/decrypt hidden parameters and resource properties data."""
    ctxt = context.get_admin_context()
    prev_encryption_key = CONF.command.previous_encryption_key
    if CONF.command.crypt_operation == "encrypt":
        utils.encrypt_parameters_and_properties(ctxt, prev_encryption_key)
    elif CONF.command.crypt_operation == "decrypt":
        utils.decrypt_parameters_and_properties(ctxt, prev_encryption_key)
Esempio n. 36
0
def do_resource_data_list():
    ctxt = context.get_admin_context()
    data = db_api.resource_data_get_all(ctxt, CONF.command.resource_id)

    print_format = "%-16s %-64s"

    for k in data.keys():
        print(print_format % (k, data[k]))
Esempio n. 37
0
    def start(self):
        super(EngineService, self).start()

        # Create a periodic_watcher_task per-stack
        admin_context = context.get_admin_context()
        stacks = db_api.stack_get_all(admin_context, tenant_safe=False)
        for s in stacks:
            self.stack_watch.start_watch_task(s.id, admin_context)
Esempio n. 38
0
    def create_stack(self, stack_name, temp, params):
        template = parser.Template(temp)
        parameters = parser.Parameters(stack_name, template, params)
        stack = parser.Stack(context.get_admin_context(), stack_name,
                             template, parameters)

        stack.store()
        return stack
Esempio n. 39
0
def do_crypt_parameters_and_properties():
    """Encrypt/decrypt hidden parameters and resource properties data."""
    ctxt = context.get_admin_context()
    prev_encryption_key = CONF.command.previous_encryption_key
    if CONF.command.crypt_operation == "encrypt":
        utils.encrypt_parameters_and_properties(ctxt, prev_encryption_key)
    elif CONF.command.crypt_operation == "decrypt":
        utils.decrypt_parameters_and_properties(ctxt, prev_encryption_key)
Esempio n. 40
0
def create_context(mocks, user='******',
                   tenant='test_admin', ctx=None):
    ctx = ctx or context.get_admin_context()
    mocks.StubOutWithMock(ctx, 'username')
    mocks.StubOutWithMock(ctx, 'tenant_id')
    ctx.username = user
    ctx.tenant_id = tenant
    return ctx
Esempio n. 41
0
 def setUp(self):
     super(WaitCondMetadataUpdateTest, self).setUp()
     setup_dummy_db()
     self.ctx = context.get_admin_context()
     self.ctx.tenant_id = 'test_tenant'
     self.fc = fakes.FakeKeystoneClient()
     self.man = service.EngineService('a-host', 'a-topic')
     cfg.CONF.set_default('heat_waitcondition_server_url',
                          'http://127.0.0.1:8000/v1/waitcondition')
Esempio n. 42
0
 def setUp(self):
     super(WaitCondMetadataUpdateTest, self).setUp()
     setup_dummy_db()
     self.ctx = context.get_admin_context()
     self.ctx.tenant_id = 'test_tenant'
     self.fc = fakes.FakeKeystoneClient()
     self.man = service.EngineService('a-host', 'a-topic')
     cfg.CONF.set_default('heat_waitcondition_server_url',
                          'http://127.0.0.1:8000/v1/waitcondition')
Esempio n. 43
0
 def list_watch_data(self, req, watch_name):
     con = context.get_admin_context()
     data = self.engine_rpcapi.list_watch_data(con,
                 watch_name=watch_name)
     if data:
         return data
     else:
         return json_error(404,
                           'The watch "%s" does not exist.' % watch_name)
Esempio n. 44
0
 def list_resources(self, req, stack_name):
     con = context.get_admin_context()
     resources = self.engine_rpcapi.metadata_list_resources(con,
                      stack_name=stack_name)
     if resources:
         return resources
     else:
         return json_error(404,
                           'The stack "%s" does not exist.' % stack_name)
Esempio n. 45
0
 def list_resources(self, req, stack_name):
     con = context.get_admin_context()
     resources = self.engine_rpcapi.metadata_list_resources(
         con, stack_name=stack_name)
     if resources:
         return resources
     else:
         return json_error(404,
                           'The stack "%s" does not exist.' % stack_name)
Esempio n. 46
0
 def create_watch_data(self, req, body, watch_name):
     con = context.get_admin_context()
     [error, watch_data
      ] = self.engine_rpcapi.create_watch_data(con,
                                               watch_name=watch_name,
                                               stats_data=body)
     if error:
         return json_error(400, error)
     return json_response(201, watch_data)
Esempio n. 47
0
    def setUp(self):
        self.username = '******'

        self.m = mox.Mox()

        self.ctx = context.get_admin_context()
        self.m.StubOutWithMock(self.ctx, 'username')
        self.ctx.username = self.username

        self.m.ReplayAll()
Esempio n. 48
0
    def setUp(self):
        self.username = '******'

        self.m = mox.Mox()

        self.ctx = context.get_admin_context()
        self.m.StubOutWithMock(self.ctx, 'username')
        self.ctx.username = self.username

        self.m.ReplayAll()
Esempio n. 49
0
    def setUp(self):
        self.username = '******'

        self.m = mox.Mox()

        self.ctx = context.get_admin_context()
        self.ctx.username = self.username
        self.ctx.tenant_id = u'123456'

        self.m.ReplayAll()
Esempio n. 50
0
    def setUp(self):
        super(WatchRuleTest, self).setUp()
        self.setUpDatabase()
        self.username = '******'

        self.ctx = context.get_admin_context()
        self.ctx.username = self.username
        self.ctx.tenant_id = u'123456'

        self.m.ReplayAll()
Esempio n. 51
0
def do_reset_stack_status():
    print(_("Warning: this command is potentially destructive and only "
            "intended to recover from specific crashes."))
    print(_("It is advised to shutdown all Heat engines beforehand."))
    print(_("Continue ? [y/N]"))
    data = moves.input()
    if not data.lower().startswith('y'):
        return
    ctxt = context.get_admin_context()
    db_api.reset_stack_status(ctxt, CONF.command.stack_id)
Esempio n. 52
0
    def setUp(self):
        self.context = context.get_admin_context()
        config.register_engine_opts()
        cfg.CONF.set_default("rpc_backend", "heat.openstack.common.rpc.impl_fake")
        cfg.CONF.set_default("verbose", True)
        cfg.CONF.set_default("engine_topic", "engine")
        cfg.CONF.set_default("host", "host")

        self.stubs = stubout.StubOutForTesting()
        super(EngineRpcAPITestCase, self).setUp()
Esempio n. 53
0
    def setUp(self):
        self.username = '******'

        self.m = mox.Mox()

        self.ctx = context.get_admin_context()
        self.ctx.username = self.username
        self.ctx.tenant_id = u'123456'

        self.m.ReplayAll()
Esempio n. 54
0
def do_migrate():
    messaging.setup()
    client = rpc_client.EngineClient()
    ctxt = context.get_admin_context()
    try:
        client.migrate_convergence_1(ctxt, CONF.command.stack_id)
    except exception.NotFound:
        raise Exception(
            _("Stack with id %s can not be found.") % CONF.command.stack_id)
    except (exception.NotSupported, exception.ActionNotComplete) as ex:
        raise Exception(ex.message)
Esempio n. 55
0
def do_reset_stack_status():
    print(
        _("Warning: this command is potentially destructive and only "
          "intended to recover from specific crashes."))
    print(_("It is advised to shutdown all Heat engines beforehand."))
    print(_("Continue ? [y/N]"))
    data = moves.input()
    if not data.lower().startswith('y'):
        return
    ctxt = context.get_admin_context()
    db_api.reset_stack_status(ctxt, CONF.command.stack_id)
Esempio n. 56
0
 def setUp(self):
     self.m = mox.Mox()
     tmpl = {'Type': 'Foo', 'Metadata': {'Test': 'Initial metadata'}}
     ctx = context.get_admin_context()
     self.m.StubOutWithMock(ctx, 'username')
     ctx.username = '******'
     self.stack = parser.Stack(ctx, 'test_stack', parser.Template({}))
     self.stack.store()
     self.res = generic_rsrc.GenericResource('metadata_resource', tmpl,
                                             self.stack)
     self.res.create()
Esempio n. 57
0
    def setUp(self):
        self.context = context.get_admin_context()
        config.register_engine_opts()
        cfg.CONF.set_default('rpc_backend',
                             'heat.openstack.common.rpc.impl_fake')
        cfg.CONF.set_default('verbose', True)
        cfg.CONF.set_default('engine_topic', 'engine')
        cfg.CONF.set_default('host', 'host')

        self.stubs = stubout.StubOutForTesting()
        super(EngineRpcAPITestCase, self).setUp()
Esempio n. 58
0
 def setUp(self):
     super(MetadataTest, self).setUp()
     tmpl = {'Type': 'Foo', 'Metadata': {'Test': 'Initial metadata'}}
     setup_dummy_db()
     ctx = context.get_admin_context()
     self.m.StubOutWithMock(ctx, 'username')
     ctx.username = '******'
     self.stack = parser.Stack(ctx, 'test_stack', parser.Template({}))
     self.stack.store()
     self.res = generic_rsrc.GenericResource('metadata_resource', tmpl,
                                             self.stack)
     scheduler.TaskRunner(self.res.create)()
Esempio n. 59
0
    def setUp(self):
        config.register_engine_opts()
        self.context = context.get_admin_context()
        cfg.CONF.set_default('rpc_backend',
                             'heat.openstack.common.rpc.impl_fake')
        cfg.CONF.set_default('verbose', True)
        cfg.CONF.set_default('host', 'host')

        self.stubs = stubout.StubOutForTesting()
        self.identity = dict(
            identifier.HeatIdentifier('engine_test_tenant', '6', 'wordpress'))
        super(EngineRpcAPITestCase, self).setUp()
Esempio n. 60
0
    def start(self):
        super(EngineService, self).start()

        # Create dummy service task, because when there is nothing queued
        # on self.tg the process exits
        self.tg.add_timer(cfg.CONF.periodic_interval, self._service_task)

        # Create a periodic_watcher_task per-stack
        admin_context = context.get_admin_context()
        stacks = db_api.stack_get_all(admin_context)
        for s in stacks:
            self._start_watch_task(s.id, admin_context)