Exemple #1
0
    def __init__(self, command_args, global_args, molecule=False):
        """
        Initialize commands

        :param command_args: arguments of the command
        :param global_args: arguments from the CLI
        :param molecule: molecule instance
        """
        self.args = docopt(self.__doc__, argv=command_args)
        self.args['<command>'] = self.__class__.__name__.lower()
        self.command_args = command_args

        self.static = False

        # give us the option to reuse an existing molecule instance
        if not molecule:
            self.molecule = Molecule(self.args)
            self.molecule.main()
        else:
            self.molecule = molecule

        # init doesn't need to load molecule files
        if self.__class__.__name__ == 'Init':
            return

        # assume static inventory if no vagrant config block is defined
        if self.molecule._provisioner is None:
            self.static = True

        # assume static inventory if no instances are defined in vagrant config block
        if self.molecule._provisioner.instances is None:
            self.static = True

        # Add or update the group_vars if needed.
        self.molecule._add_or_update_group_vars()
    def setUp(self):
        super(TestDockerProvisioner, self).setUp()
        # Setup mock molecule
        self._mock_molecule = Molecule(dict())

        self.temp = '/tmp/test_config_load_defaults_external_file.yml'
        data = {
            'molecule': {
                'molecule_dir': '.test_molecule',
                'inventory_file': 'tests/ansible_inventory'
            },
            'docker': {
                'containers': [{
                    'name': 'test1',
                    'image': 'ubuntu',
                    'image_version': 'latest',
                    'ansible_groups': ['group1']
                }, {
                    'name': 'test2',
                    'image': 'ubuntu',
                    'image_version': 'latest',
                    'ansible_groups': ['group2']
                }]
            },
            'ansible': {
                'config_file': 'test_config',
                'inventory_file': 'test_inventory'
            }
        }

        with open(self.temp, 'w') as f:
            f.write(yaml.dump(data, default_flow_style=True))

        self._mock_molecule._config.load_defaults_file(defaults_file=self.temp)

        self._mock_molecule._state = dict()
Exemple #3
0
 def setUp(self):
     super(TestStringMethods, self).setUp()
     with patch('molecule.core.Molecule._main') as mocked:
         mocked.return_value = None
         self.molecule = Molecule(None)