Exemplo n.º 1
1
def test_enactor_pass():
    uds = UDS.instantiate(protocol='dict')
    for infra in infracfg.infrastructures:
        yield make_enactor_pass, infra, uds
Exemplo n.º 2
0
    def test_create_using_ip(self):
        node_def = cfg.node_defs['node_lpds']
        self.ch = CloudHandler(self.cfg)
        self.sc = sc.ServiceComposer.instantiate(protocol='dummy')
        self.uds = UDS.instantiate(protocol='dict')
        self.uds.kvstore.set_item('node_def:test', [node_def])
        mib = ib.InfoRouter(main_info_broker=True, sub_providers=[
            self.uds,
            self.sc,
            dsp.DynamicStateProvider(self.sc, self.ch),
            sp.SynchronizationProvider(),
            CloudHandlerProvider(self.ch)
        ])

        eid = str(uuid.uuid4())
        nid = str(uuid.uuid4())
        node_desc = dict(
            infra_id=eid,
            node_id=nid,
            type='test',
            user_id=1,
            name='test')
        infrap = ip.InfraProcessor.instantiate(
            'basic', self.uds, self.ch, self.sc)
        cmd_cre = infrap.cri_create_infrastructure(eid)
        cmd_crn = infrap.cri_create_node(node_desc)
        infrap.push_instructions(cmd_cre)
        node = infrap.push_instructions(cmd_crn)[0]
        status = mib.get('node.resource.state', node)
        self.drop_nodes.append(dict(instance_id=nid, node_id="test"))
Exemplo n.º 3
0
    def test_full_dryrun(self):
        self.ch = CloudHandler(self.cfg)
        with util.global_dry_run():
            nid = self.ch.create_node(cfg.node_defs['node1'])

            self.sc = sc.ServiceComposer.instantiate(protocol='dummy')
            self.uds = UDS.instantiate(protocol='dict')
            mib = ib.real_main_info_broker = \
                ib.InfoRouter(sub_providers=[
                    self.uds,
                    self.sc,
                    dsp.DynamicStateProvider(self.sc, self.ch),
                    sp.SynchronizationProvider(),
                    CloudHandlerProvider(self.ch)
                ])

            try:
                log.debug(mib.get('node.resource.state',
                                  dict(instance_id=nid,
                                       node_id="test",
                                       backend_id='lpds')))
            finally:
                self.ch.drop_node(dict(instance_id=nid,
                                       node_id="test",
                                       backend_id='lpds'))
Exemplo n.º 4
0
def make_upkeep(uds_config):
    import copy
    infra = copy.deepcopy(infracfg.infrastructures[0])
    uds = UDS.instantiate(**uds_config)
    e, buf, statd = make_enactor_pass(
        infra,
        uds,
        upkeep_strategy='basic')
    nose.tools.assert_equal(buf.getvalue(),
                            infra['expected_output'])

    statekey = 'infra:{0}:state'.format(statd.infra_id)
    failedkey = 'infra:{0}:failed_nodes'.format(statd.infra_id)
    dynstate = uds.kvstore[statekey]
    origstate = copy.deepcopy(dynstate)

    dynstate['C'].values()[1]['state'] = nodestate.SHUTDOWN
    dynstate['A'].values()[0]['state'] = nodestate.FAIL
    uds.kvstore[statekey] = dynstate
    e.make_a_pass()

    dynstate = uds.kvstore[statekey]
    nose.tools.assert_equal((len(dynstate['A']), len(dynstate['C'])),
                            (len(origstate['A']), len(origstate['C'])))

    nose.tools.assert_equal(
        uds.kvstore[failedkey].values()[0]['node_id'],
        origstate['A'].values()[0]['node_id'])
Exemplo n.º 5
0
    def test_create_using_ip(self):
        node_def = cfg.node_defs['node_lpds']
        self.ch = ResourceHandler(self.cfg)
        self.sc = sc.ConfigManager.instantiate(protocol='dummy')
        self.uds = UDS.instantiate(protocol='dict')
        self.uds.kvstore.set_item('node_def:test', [node_def])
        mib = ib.InfoRouter(main_info_broker=True,
                            sub_providers=[
                                self.uds, self.sc,
                                dsp.DynamicStateProvider(self.sc, self.ch),
                                sp.SynchronizationProvider(),
                                ResourceHandlerProvider(self.ch)
                            ])

        eid = str(uuid.uuid4())
        nid = str(uuid.uuid4())
        node_desc = dict(infra_id=eid,
                         node_id=nid,
                         type='test',
                         user_id=1,
                         name='test')
        infrap = ip.InfraProcessor.instantiate('basic', self.uds, self.ch,
                                               self.sc)
        cmd_cre = infrap.cri_create_infrastructure(eid)
        cmd_crn = infrap.cri_create_node(node_desc)
        infrap.push_instructions(cmd_cre)
        node = infrap.push_instructions(cmd_crn)[0]
        status = mib.get('node.resource.state', node)
        self.drop_nodes.append(dict(instance_id=nid, node_id="test"))
Exemplo n.º 6
0
def make_upkeep(uds_config):
    import copy
    infra = copy.deepcopy(infracfg.infrastructures[0])
    uds = UDS.instantiate(**uds_config)
    e, buf, statd = make_enactor_pass(
        infra,
        uds,
        upkeep_strategy='basic')
    nose.tools.assert_equal(buf.getvalue(),
                            infra['expected_output'])

    statekey = 'infra:{0}:state'.format(statd.infra_id)
    failedkey = 'infra:{0}:failed_nodes'.format(statd.infra_id)
    dynstate = uds.kvstore[statekey]
    origstate = copy.deepcopy(dynstate)

    list(dynstate['C'].values())[1]['state'] = nodestate.SHUTDOWN
    list(dynstate['A'].values())[0]['state'] = nodestate.FAIL
    uds.kvstore[statekey] = dynstate
    e.make_a_pass()

    dynstate = uds.kvstore[statekey]
    nose.tools.assert_equal((len(dynstate['A']), len(dynstate['C'])),
                            (len(origstate['A']), len(origstate['C'])))

    nose.tools.assert_equal(
        list(uds.kvstore[failedkey].values())[0]['node_id'],
        list(origstate['A'].values())[0]['node_id'])
Exemplo n.º 7
0
    def test_full_dryrun(self):
        self.ch = ResourceHandler(self.cfg)
        with util.global_dry_run():
            nid = self.ch.create_node(cfg.node_defs['node1'])

            self.sc = sc.ConfigManager.instantiate(protocol='dummy')
            self.uds = UDS.instantiate(protocol='dict')
            mib = ib.real_main_info_broker = \
                ib.InfoRouter(sub_providers=[
                    self.uds,
                    self.sc,
                    dsp.DynamicStateProvider(self.sc, self.ch),
                    sp.SynchronizationProvider(),
                    ResourceHandlerProvider(self.ch)
                ])

            try:
                log.debug(
                    mib.get(
                        'node.resource.state',
                        dict(instance_id=nid,
                             node_id="test",
                             backend_id='lpds')))
            finally:
                self.ch.drop_node(
                    dict(instance_id=nid, node_id="test", backend_id='lpds'))
Exemplo n.º 8
0
 def setUp(self):
     ib.set_all_singletons(
         DummyInfoBroker(),
         UDS.instantiate(protocol='dict'),
         None,
         DummyCloudHandler(),
         DummyConfigManager(),
     )
Exemplo n.º 9
0
 def setUp(self):
     ib.set_all_singletons(
         DummyInfoBroker(),
         UDS.instantiate(protocol='dict'),
         None,
         DummyCloudHandler(),
         DummyConfigManager(),
     )
Exemplo n.º 10
0
 def setUp(self):
     ib.set_all_singletons(
         DummyInfoBroker(),
         UDS.instantiate(protocol='dict'),
         None,
         DummyCloudHandler(),
         DummyServiceComposer(),
     )
Exemplo n.º 11
0
 def setUp(self):
     ib.set_all_singletons(
         DummyInfoBroker(),
         UDS.instantiate(protocol='dict'),
         el.EventLog.instantiate(protocol='logging'),
         DummyCloudHandler(),
         DummyConfigManager(),
     )
     self.ib = ib.real_main_info_broker
Exemplo n.º 12
0
 def setUp(self):
     ib.set_all_singletons(
         DummyInfoBroker(),
         UDS.instantiate(protocol="dict"),
         el.EventLog.instantiate(protocol="logging"),
         DummyCloudHandler(),
         DummyServiceComposer(),
     )
     self.ib = ib.real_main_info_broker
Exemplo n.º 13
0
def test_drop_nodes():
    import copy
    infra = copy.deepcopy(infracfg.infrastructures[0])
    uds = UDS.instantiate(protocol='dict')
    e, buf, statd = make_enactor_pass(infra, uds)
    nose.tools.assert_equal(buf.getvalue(), infra['expected_output'])
    sc = infra['nodes'][2]['scaling']
    sc['min'] = sc['max'] = 1
    e.make_a_pass()
Exemplo n.º 14
0
 def setUp(self):
     ib.set_all_singletons(
         DummyInfoBroker(),
         UDS.instantiate(protocol='dict'),
         el.EventLog.instantiate(protocol='logging'),
         DummyCloudHandler(),
         DummyConfigManager(),
     )
     self.ib = ib.real_main_info_broker
Exemplo n.º 15
0
def test_drop_nodes():
    import copy
    infra = copy.deepcopy(infracfg.infrastructures[0])
    uds = UDS.instantiate(protocol='dict')
    e, buf, statd = make_enactor_pass(infra, uds)
    nose.tools.assert_equal(buf.getvalue(),
                            infra['expected_output'])
    sc = infra['nodes'][2]['scaling']
    sc['min'] = sc['max'] = 1
    e.make_a_pass()
Exemplo n.º 16
0
    def test_suspend(self):
        sd = StaticDescription(dict(name='',
                                    nodes=[],
                                    user_id=None))
        infraid = sd.infra_id
        uds = UDS.instantiate(self.protocol, **self.config)
        uds.add_infrastructure(sd)

        self.assertFalse(uds.get_static_description(infraid).suspended)
        uds.suspend_infrastructure(
            infraid, reason=Exception('something something daark siide'))
        self.assertTrue(uds.get_static_description(infraid).suspended)
        uds.resume_infrastructure(infraid)
        self.assertFalse(uds.get_static_description(infraid).suspended)
Exemplo n.º 17
0
 def test_infra(self):
     infraid = self.uuid
     state_infrakey = 'infra:{0!s}:state'.format(infraid)
     failed_infrakey = 'infra:{0!s}:failed_nodes'.format(infraid)
     uds = UDS.instantiate(self.protocol, **self.config)
     instances = [dict(node_id='1', name='A', infra_id=infraid),
                  dict(node_id='2', name='A', infra_id=infraid),
                  dict(node_id='3', name='B', infra_id=infraid)]
     for i in instances:
         uds.register_started_node(infraid, i['name'], i)
     self.assertEqual(uds.get_infrastructure_state(infraid),
                      dict(A={'1': instances[0], '2': instances[1]},
                           B={'3': instances[2]}))
     uds.remove_nodes(infraid, '2', '3')
     self.assertEqual(uds.get_infrastructure_state(infraid),
                      dict(A={'1': instances[0]}))
     uds.store_failed_nodes(infraid, instances[1], instances[2])
     self.assertEqual(uds.kvstore.query_item(failed_infrakey),
                      {'2': instances[1],
                       '3': instances[2]})
Exemplo n.º 18
0
    def test_node_status(self):
        self.ch = ResourceHandler(self.cfg)
        last_exception = None

        self.sc = sc.ConfigManager.instantiate(protocol='dummy')
        self.uds = UDS.instantiate(protocol='dict')
        mib = ib.InfoRouter(main_info_broker=True,
                            sub_providers=[
                                self.uds, self.sc,
                                dsp.DynamicStateProvider(self.sc, self.ch),
                                sp.SynchronizationProvider(),
                                ResourceHandlerProvider(self.ch)
                            ])

        for i in self.drop_nodes:
            try:
                node_state = mib.get('node.resource.state', i)
                log.info("Status of node %r is %r", i, node_state)
            except Exception as ex:
                log.exception('Failure:')
                last_exception = ex
        if last_exception:
            raise last_exception, None, sys.exc_info()[2]
Exemplo n.º 19
0
    def test_node_status(self):
        self.ch = CloudHandler(self.cfg)
        last_exception = None

        self.sc = sc.ServiceComposer.instantiate(protocol='dummy')
        self.uds = UDS.instantiate(protocol='dict')
        mib = ib.InfoRouter(main_info_broker=True, sub_providers=[
            self.uds,
            self.sc,
            dsp.DynamicStateProvider(self.sc, self.ch),
            sp.SynchronizationProvider(),
            CloudHandlerProvider(self.ch)
        ])

        for i in self.drop_nodes:
            try:
                node_state = mib.get('node.resource.state', i)
                log.info("Status of node %r is %r", i, node_state)
            except Exception as ex:
                log.exception('Failure:')
                last_exception = ex
        if last_exception:
            raise last_exception, None, sys.exc_info()[2]
Exemplo n.º 20
0
 def test_inst(self):
     self.uds = ib.real_main_uds = UDS.instantiate(self.protocol, **self.config)
     self.assertEqual(ib.main_uds.register_started_node,
                      self.uds.register_started_node)
Exemplo n.º 21
0
def test_enactor_pass():
    uds = UDS.instantiate(protocol='dict')
    for infra in infracfg.infrastructures:
        yield make_enactor_pass, infra, uds