Ejemplo n.º 1
0
    def test_paramikoWrap(self):
        print 'test_paramikoWrap pass'
        # arrange
        s = Stack.Instance()

        # act
        res = s.paramikoWrap(Util.randomString, Util.randomString)

        # assert
        self.assertEqual(res, [1])
Ejemplo n.º 2
0
    def test_addHost_name_empty(self):
        # arrange
        s = Stack.Instance()

        # act
        res = s.addHost(Util.emptyString, Util.emptyString, Util.emptyString,
                        Util.emptyString)

        # assert
        self.assertFalse(res)
Ejemplo n.º 3
0
    def test_getRandomInt(self, getRandomInt_mock):
        # arrange
        s = Stack.Instance()
        getRandomInt_mock.return_value = 1

        # act
        res = s.getRandomInt(random.random())

        # assert
        self.assertEqual(res, 1)
Ejemplo n.º 4
0
    def test_addHost_component_null_name_not_equals_host(self):
        # arrange
        s = Stack.Instance()

        # act
        res = s.addHost(Util.randomString, None, Util.emptyString,
                        Util.emptyString)

        # assert
        self.assertFalse(res)
Ejemplo n.º 5
0
    def test_updateServicesState(self):
        # arrange
        s = Stack.Instance()
        s.hosts = {}

        # act
        res = s.getHostList()
        print 'res: ', res

        # assert
        self.assertEqual(res, [])
Ejemplo n.º 6
0
class InfoParser(object):
    # parse the inventory file and generate a stack instance
    inventory = '/etc/openstack_deploy/openstack_inventory.json'
    logger.info(inventory)
    stack = Stack.Instance()

    def __init__(self):
        with open(self.inventory) as data_file:
            data = yaml.safe_load(data_file)

            if data and data['_meta'] and data['_meta']['hostvars']:
                try:
                    for key, value in data['_meta']['hostvars'].iteritems():
                        self.stack.addHost(key, value['physical_host'],
                                           value['container_address'],
                                           value['component'])
                except:
                    logger.error(str(inspect.stack()[0][3]))
                    logger.info('calling func : ' +
                                str(inspect.stack()[1][3]) + '() from ' +
                                str(inspect.stack()[1][1]))

    def getStackInstance(self):
        return self.stack
Ejemplo n.º 7
0
class MyTestCase(unittest.TestCase):
    def test_addHost_name_empty(self):
        # arrange
        s = Stack.Instance()

        # act
        res = s.addHost(Util.emptyString, Util.emptyString, Util.emptyString,
                        Util.emptyString)

        # assert
        self.assertFalse(res)

    def test_addHost_component_null_name_equals_host(self):
        # arrange
        s = Stack.Instance()

        # act
        res = s.addHost(Util.randomString, None, Util.emptyString,
                        Util.randomString)

        # assert
        self.assertTrue(res)

    def test_addHost_component_not_null_name_not_equals_host(self):
        # arrange
        s = Stack.Instance()

        # act
        res = s.addHost(Util.randomString, Util.randomString, Util.emptyString,
                        Util.emptyString)

        # assert
        self.assertTrue(res)

    def test_addHost_component_null_name_not_equals_host(self):
        # arrange
        s = Stack.Instance()

        # act
        res = s.addHost(Util.randomString, None, Util.emptyString,
                        Util.emptyString)

        # assert
        self.assertFalse(res)

    @mock.patch.object(Stack.Instance(), 'getRandomInt')
    def test_getRandomInt(self, getRandomInt_mock):
        # arrange
        s = Stack.Instance()
        getRandomInt_mock.return_value = 1

        # act
        res = s.getRandomInt(random.random())

        # assert
        self.assertEqual(res, 1)

    def test_getHostList(self):
        # arrange
        s = Stack.Instance()
        s.hosts = {}

        # act
        res = s.getHostList()
        print 'res: ', res

        # assert
        self.assertEqual(res, [])

    def test_updateServicesState(self):
        # arrange
        s = Stack.Instance()
        s.hosts = {}

        # act
        res = s.getHostList()
        print 'res: ', res

        # assert
        self.assertEqual(res, [])

    def test_paramikoWrap(self):
        print 'test_paramikoWrap pass'
        # arrange
        s = Stack.Instance()

        # act
        res = s.paramikoWrap(Util.randomString, Util.randomString)

        # assert
        self.assertEqual(res, [1])