Exemplo n.º 1
0
    def main(self, argv):
        self.parser = self.get_base_parser()
        run_setup.add_arguments(self.parser)
        (options, args) = self.parser.parse_known_args(argv)
        utils.setup_debugging(options.debug)

        LOG.debug('Starting clearstack')

        if not argv or options.help:
            self.do_help(options)
            return 0

        if options.gen_keys:
            LOG.debug('generating ssh keys')
            utils.generate_ssh_keys(options.gen_keys)

        # todo: fix
        # if options.allinone:
        #     LOG.debug('testing root access')
        #     if os.geteuid() != 0:
        #         LOG.error("clearstack: error: you need to have root access")
        #         sys.exit(1)

        """ Save user's variables, used to read/write answerfile """
        variables_cmd = {k: v for (k, v) in options.__dict__.items()
                         if v is not None and k.startswith("CONFIG_")}

        ansfile = AnswerFile.get()
        if options.gen_answer_file:
            LOG.debug('generating answer file')
            ansfile.generate(options.gen_answer_file, variables_cmd)

        if options.answer_file:
            try:
                LOG.debug('Reading answer file')
                ansfile.read(options.answer_file, variables_cmd)
                LOG.debug('Running all sequences')
                run_setup.run_all_sequences()
            except Exception as e:
                LOG.error("clearstack: {0}".format(str(e)))
                sys.exit(1)
            LOG.debug('Generating admin-openrc')
            run_setup.generate_admin_openrc()
Exemplo n.º 2
0
 def test_read_non_existing_file(self, mock_isfile):
     mock_isfile.side_effect = [False]
     filename = '/tmp/clearstack.answerfile'
     self.assertRaises(IOError, AnswerFile.get().read, filename, {})
Exemplo n.º 3
0
 def test_generate_file(self):
     m = mock.mock_open()
     filename = '/tmp/clearstack.answerfile'
     with mock.patch('clearstack.answer_file.open', m, create=True):
         AnswerFile.get().generate(filename, {})
     m.assert_called_once_with(filename, 'w')