示例#1
0
    def test_daemon_last_lots(self, m_exit, m_gc):
        conf = {'commands': {}}
        for cc in range(0, 99):
            cmd = {'c-%d' % cc: {'command': 'true'}}
            conf['commands'].update(cmd)

        conf['commands'].update(
            {'c-last': {'daemon': True, 'command': 'true'}})

        for cc in range(100, 200):
            cmd = {'c-%d' % cc: {'command': 'true'}}
            conf['commands'].update(cmd)
        exp = conf['commands']

        conf_base_node = '/kolla/deploy_id/config/testg/testr'

        def run_record(run_self):
            print(run_self)
            run_self.time_slept = 120
            if run_self.daemon:
                self.assertEqual(1, len(exp))
            del exp[run_self.name]
            return 0
        # Mocking Command's method in decorator doesn't work
        with mock.patch.object(start.Command, 'run', autospec=True) as m_run:
            m_run.side_effect = run_record
            start.run_commands(self.client, conf, conf_base_node)
            self.assertEqual(200, len(m_run.mock_calls))
            self.assertEqual([], m_exit.mock_calls)
示例#2
0
    def test_one_bad(self, m_exit, m_gc, m_run):
        conf = {'commands': {'setup': {
            'run_once': True,
            'command': 'true'}}}

        m_run.return_value = 3
        start.run_commands(self.client, conf)
        m_run.assert_called_once_with(mock.ANY)
        self.assertEqual([mock.call(1)], m_exit.mock_calls)
示例#3
0
    def test_one_bad(self, m_exit, m_gc, m_run):
        cmd = {'setup': {
            'run_once': True,
            'command': 'true'}}

        conf = {'commands': cmd}
        conf_base_node = '/kolla/deploy_id/config/testg/testr'
        m_run.return_value = 3
        start.run_commands(self.client, conf, conf_base_node)
        m_run.assert_called_once_with(mock.ANY)
        self.assertEqual([mock.call(1)], m_exit.mock_calls)
示例#4
0
 def test_missing_variable(self, m_wf, m_gar, m_gip, m_rt, m_sleep):
     afile = {'afile': {
         'source': 'config/mariadb/templates/galera.cnf.j2',
         'dest': '/etc/mysql_dir/my.cnf',
         'owner': 'nobody',
         'perm': "0600"}}
     conf = {'commands': {'setup': {
         'command': 'true', 'files': afile}}}
     m_gar.return_value = {}, {}
     m_rt.return_value = ''
     self.client.create('/kolla/deploy_id/testg/testr/files/afile',
                        '{{ xyz }}'.encode('utf-8'), makepath=True)
     start.run_commands(self.client, conf)
     m_wf.assert_called_once_with(afile['afile'], '')
示例#5
0
    def test_one_bad_retry(self, m_exit, m_gc, m_run):
        conf = {'commands': {'setup': {
            'run_once': True,
            'retries': 2,
            'delay': 0,
            'command': 'true'}}}

        self.returns = 0

        def run_effect(run_self):
            if self.returns == 0:
                self.returns = 1
                return 3
            return 0
        m_run.side_effect = run_effect
        start.run_commands(self.client, conf)
        self.assertEqual([mock.call(mock.ANY), mock.call(mock.ANY)],
                         m_run.mock_calls)
        self.assertEqual([], m_exit.mock_calls)
示例#6
0
    def test_one_bad_retry(self, m_exit, m_gc, m_run):
        cmd = {'setup': {
            'run_once': True,
            'retries': 2,
            'delay': 0,
            'command': 'true'}}

        conf = {'commands': cmd}

        conf_base_node = '/kolla/deploy_id/config/testg/testr'
        self.returns = 0

        def run_effect(run_self):
            if self.returns == 0:
                self.returns = 1
                return 3
            return 0
        m_run.side_effect = run_effect
        start.run_commands(self.client, conf, conf_base_node)
        self.assertEqual([mock.call(mock.ANY), mock.call(mock.ANY)],
                         m_run.mock_calls)
        self.assertEqual([], m_exit.mock_calls)
示例#7
0
    def test_nova_conf(self, m_write_file, m_get_ip, m_gethost, m_sleep):
        m_get_ip.return_value = '1.2.3.4'
        m_gethost.return_value = 'test-hostname'

        # register local host group.
        start.register_group_and_hostvars(self.client)

        self._register_service('openstack/nova/nova-compute', ['4.4.4.4'])
        self._register_service('infra/memcached/memcached',
                               ['3.1.2.3', '3.1.2.4'])
        self._register_service('infra/rabbitmq/rabbitmq',
                               ['2.1.2.3', '2.1.2.4'])
        self._register_service('openstack/glance/glance-api',
                               ['1.1.2.3', '1.1.2.4'])
        self._define_variables()

        afile = {'source': 'nova.conf.j2',
                 'dest': '/etc/nova/nova.conf',
                 'owner': 'nova',
                 'perm': '0600'}

        conf = {'commands': {'setup': {
            'command': 'true', 'files': {'afile': afile}}}}

        mod_dir = os.path.dirname(sys.modules[__name__].__file__)
        proj_dir = os.path.abspath(os.path.join(mod_dir, '..', '..', '..'))
        with open(os.path.join(proj_dir,
                  'config/nova/templates/nova.conf.j2')) as nc:
            template_contents = nc.read()
            self.client.create(
                '/kolla/did/openstack/nova/nova-compute/files/afile',
                template_contents.encode('utf-8'), makepath=True)

        cmp_file = os.path.join(mod_dir, 'nova-%s.conf' % self.out)
        with open(cmp_file) as cf:
            expect = cf.read()

        start.run_commands(self.client, conf)
        m_write_file.assert_called_once_with(afile, expect)