예제 #1
0
 def make_restore_command(self, backup_filename):
     options = Options(self.db_connection_options)
     options.update(self.db_restore_options)
     options.update([
         ('dbname', 'template1'),  # use any existing DB
         ('jobs', str(self.db_restore_workers)),
         ('file', os.path.join(self.db_backup_dir, backup_filename)),
     ])
     return 'pg_restore {options}'.format(options=options)
예제 #2
0
 def make_backup_command(self):
     options = Options(self.db_connection_options)
     options.update(self.db_backup_options)
     options.update([
         ('format', self.db_backup_format),
         ('dbname', self.db_name),
         ('compress', self.db_backup_compress_level),
         ('jobs', self.db_backup_workers),
         ('file', os.path.join(
             self.db_backup_dir,
             self.db_backup_filename.format(datetime=datetime.utcnow())
         )),
     ])
     return 'pg_dump {options}'.format(options=options)
예제 #3
0
 def prepare(self, tag=None, no_cache=False):
     """
     prepare Docker image
     """
     options = Options([
         ('tag', str(self.image[self.registry:tag])),
         ('no-cache', strtobool(no_cache)),
         ('pull', True),
     ])
     fabricio.local(
         'docker build {options} {build_path}'.format(
             build_path=self.build_path,
             options=options,
         ),
         quiet=False,
         use_cache=True,
     )
     self.delete_dangling_images()
예제 #4
0
 def make_container_options(cls, temporary=None, name=None, options=()):
     options = dict(options)
     container_options = Options()
     for remap, option in cls.container_options_mapping:
         container_options[remap] = options.pop(option, None)
     container_options.update(
         (
             ('name', name),
             ('rm', temporary),
             ('tty', temporary),
             ('interactive', temporary),
             ('detach', temporary is not None and not temporary),
         ),
         **options
     )
     if temporary:
         # temporary containers can't be restarted
         container_options['restart'] = None
     return container_options
예제 #5
0
 def db_backup_options(self):
     return Options([
         ('if-exists', True),
         ('create', True),
         ('clean', True),
     ])
예제 #6
0
 def db_connection_options(self):
     return Options([
         ('username', self.db_user),
         ('host', self.db_host),
         ('port', self.db_port),
     ])
예제 #7
0
 def test_str_version(self):
     cases = dict(
         # TODO all values must be quoted
         empty_options_list=dict(
             options=OrderedDict(),
             expected_str_version='',
         ),
         with_underscore=dict(
             options=OrderedDict(foo_baz='bar'),
             expected_str_version='--foo_baz bar',
         ),
         multiword=dict(
             options=OrderedDict(foo='bar baz'),
             expected_str_version='--foo "bar baz"',
         ),
         empty=dict(
             options=OrderedDict(foo=''),
             expected_str_version='--foo ""',
         ),
         with_single_quotes=dict(
             options=OrderedDict(foo="'bar'"),
             expected_str_version='--foo "\'bar\'"',
         ),
         with_double_quotes=dict(
             options=OrderedDict(foo='"bar"'),
             expected_str_version='--foo "\\"bar\\""',
         ),
         with_quotes_and_spaces=dict(
             options=OrderedDict(foo='"bar" \'baz\''),
             expected_str_version='--foo "\\"bar\\" \'baz\'"',
         ),
         single_length=dict(
             options=OrderedDict(foo='bar'),
             expected_str_version='--foo bar',
         ),
         integer=dict(
             options=OrderedDict(foo=42),
             expected_str_version='--foo 42',
         ),
         triple_length=dict(
             options=OrderedDict([
                 ('foo', 'foo'),
                 ('bar', 'bar'),
                 ('baz', 'baz'),
             ]),
             expected_str_version='--foo foo --bar bar --baz baz',
         ),
         multi_value=dict(
             options=OrderedDict(foo=['bar', 'baz']),
             expected_str_version='--foo bar --foo baz',
         ),
         boolean_values=dict(
             options=OrderedDict(foo=True, bar=False),
             expected_str_version='--foo',
         ),
         mix=dict(
             options=OrderedDict([
                 ('foo', 'foo'),
                 ('bar', True),
                 ('baz', ['1', 'a']),
             ]),
             expected_str_version='--foo foo --bar --baz 1 --baz a',
         ),
         # TODO empty value
         # TODO escaped value
     )
     for case, params in cases.items():
         with self.subTest(case=case):
             options = Options(params['options'])
             expected_str_version = params['expected_str_version']
             self.assertEqual(expected_str_version, str(options))