def test_create_template(self): config.registry['test'] = 'test2' executor = TemplateExecutor(src='tests/unit/helpers/template.txt', dest='test') executor.sequence = Sequence(executors=[]) executor.host = Localhost() self.assertEqual(executor.commands(), 'printf \'test test2 localhost\' | tee test')
def test_run(self): # Host and the empty mock host = Localhost() empty_mock = Mock() # Mock the result result = Result(Status.SUCCESS) result.print_line = empty_mock # Mock the execute function execute = Mock() execute.return_value = result # Mock the executor executor = CommandExecutor('ls') executor.execute = execute # Mock thread behaviour join = Mock() start = Mock() executor.start = start executor.join = join sequence = Sequence( hosts=[host], executors=[ executor ] ) sequence.print_title = empty_mock sequence.run() execute.called_with() join.called_with() start.called_with()
class TagsTest(unittest.TestCase): """ Tests if the right response is returned when some tags are set """ sequence = Sequence(executors=[]) def test_no_tags_no_skip_tags(self): config.tags = [] config.skip_tags = [] self.assertTrue(self.sequence.has_tags(get_executor())) def test_with_tags_no_skip_no_tags_in_executor(self): config.tags = ['tag1'] config.skip_tags = [] self.assertFalse(self.sequence.has_tags(get_executor())) def test_no_tags_with_skip_no_tags_in_executor(self): config.tags = [] config.skip_tags = ['tag1'] self.assertTrue(self.sequence.has_tags(get_executor())) def test_with_tags_no_skip_tags_tags_in_executor(self): config.tags = ['tag1'] config.skip_tags = [] self.assertTrue(self.sequence.has_tags(get_executor(tags=['tag1', 'tag2']))) def test_with_tags_no_skip_tags_tags_not_in_executor(self): config.tags = ['tag1'] config.skip_tags = [] self.assertFalse(self.sequence.has_tags(get_executor(tags=['tag2']))) def test_no_tags_with_skip_tags_skip_tags_in_executor(self): config.tags = [] config.skip_tags = ['tag2'] self.assertFalse(self.sequence.has_tags(get_executor(tags=['tag1', 'tag2']))) def test_no_tags_with_skip_tags_skip_tags_not_in_executor(self): config.tags = [] config.skip_tags = ['tag2'] self.assertTrue(self.sequence.has_tags(get_executor(tags=['tag1']))) def test_tags_and_skip_tags_in_executor(self): """ This test the priority of the config.tags over config.skip_tags """ config.tags = ['tag1'] config.skip_tags = ['tag1'] self.assertTrue(self.sequence.has_tags(get_executor(tags=['tag1']))) @classmethod def tearDownClass(cls): config.tags = [] config.skip_tags = []
from crit.executors.docker import DockerInstallExecutor from crit.executors.utils import TemplateExecutor from crit.sequences import Sequence from executors.create_users import user_executors sequence = Sequence( executors=[ DockerInstallExecutor(), TemplateExecutor(src='templates/docker_daemon.json', dest='/etc/docker/daemon.json', extra_vars={ 'docker_registry': '192.168.200.101:5000' }, tags=['daemon_docker'], sudo=True) ] + user_executors )
from crit.config import Localhost from crit.executors.docker import DockerInstallExecutor from crit.executors.utils import CommandExecutor, TemplateExecutor from crit.sequences import Sequence sequence = Sequence( hosts=[Localhost()], executors=[ DockerInstallExecutor(), CommandExecutor(command='usermod -a -G docker vagrant', sudo=True), TemplateExecutor(src='templates/docker_daemon.json', dest='/etc/docker/daemon.json', extra_vars={ 'docker_registry': 'localhost:5000' }, tags=['daemon_docker'], sudo=True) ] )
'max_lease_ttl': '720h', 'ui': True, 'listener': [{ 'tcp': { 'address': '0.0.0.0:8200', 'tls_disable': 1 } }] } sequence = Sequence( hosts=[slave1.slave1], executors=server_setup_sequence.executors + [ DockerRunExecutor(image='vault server', name='Run docker vault', tag='vault', environment={ 'VAULT_LOCAL_CONFIG': "'" + json.dumps(vault_config) + "'" }, ports={8200: 8200}, extra_commands='--cap-add=IPC_LOCK', tty=True, sudo=True), DockerRunExecutor(image='registry:2', name='Run registry', tag='registry', ports={5000: 5000}, sudo=True) ])
registry_url = '192.168.200.101:5000' registry_url_image = f'192.168.200.101:5000/{repo}' directory = f'/vagrant/projects/{repo}' executors = [ GitExecutor(repository=f'[email protected]:jessielaf/{repo}', chdir=directory, force=True, hosts=[Localhost()]), DockerBuildExecutor(name='Build docker image', tag=repo, chdir=directory, sudo=True, hosts=[Localhost()]), DockerTagExecutor(name='Tag docker image', tag=repo, registry_url=registry_url_image, sudo=True, hosts=[Localhost()]), DockerPushExecutor(name='Push docker image to registry', registry_url=registry_url_image, sudo=True, hosts=[Localhost()]), DockerPullExecutor(name='Pulls the image from the private repository', registry_url=registry_url, image=repo, sudo=True) ] sequence = Sequence(executors=executors)
from crit.executors.utils import CommandExecutor from crit.sequences import Sequence sequence = Sequence(executors=[CommandExecutor(command='ls')])
from crit.executors.utils import CommandExecutor from crit.sequences import Sequence print('Docker id: ') docker_container = input() sequence = Sequence( executors=[ CommandExecutor( command=f'docker container stop {docker_container}', sudo=True, name='Stop docker container' ), CommandExecutor( command=f'docker container rm {docker_container}', sudo=True, name='Remove docker container' ) ] )