def test_publish_create_repo(): """Test if creating repo publishes works.""" with test.clean_and_config(os.path.join( _test_base, b"publish_repo.yml", )) as (tyml, config): do_repo_create(config) args = [ '-c', config, 'publish', 'create', ] main(args) args = [ '-c', config, 'publish', 'update', ] main(args) state = SystemStateReader() state.read() assert set( ['centrify latest'] ) == state.publishes assert {'centrify latest': set([])} == state.publish_map
def test_publish_create_repo(): """Test if creating repo publishes works.""" with test.clean_and_config(os.path.join( _test_base, b"publish_repo.yml", )) as (tyml, config): do_repo_create(config) args = [ '-c', config, 'publish', 'create', ] main(args) args = [ '-c', config, 'publish', 'update', ] main(args) state = SystemStateReader() state.read() assert set(['centrify latest']) == state.publishes assert {'centrify latest': set([])} == state.publish_map
def test_publish_updating_basic(): """Test if updating publishes works.""" with test.clean_and_config(os.path.join( _test_base, b"publish.yml", )) as (tyml, config): do_publish_create(config) with freezegun.freeze_time("2012-10-11 10:10:10"): args = ['-c', config, 'snapshot', 'create'] main(args) args = ['-c', config, 'publish', 'update'] main(args) state = SystemStateReader() state.read() expect = set([ 'archived-fakerepo01-20121011T1010Z', 'fakerepo01-20121011T0000Z', 'fakerepo02-20121006T0000Z', 'fakerepo01-20121010T0000Z', ]) assert expect == state.snapshots expect = { 'fakerepo02 main': set(['fakerepo02-20121006T0000Z']), 'fakerepo01 main': set(['fakerepo01-20121011T0000Z']) } assert expect == state.publish_map
def do_mirror_update(config): """Test if updating mirrors works.""" args = [ '-c', config, 'mirror', 'create' ] state = SystemStateReader() state.read() assert "fakerepo01" not in state.mirrors main(args) state.read() assert "fakerepo01" in state.mirrors args[3] = 'update' main(args) args = [ 'aptly', 'mirror', 'show', ] args01 = list(args) args01.append("fakerepo01") aptly_state = test.execute_and_parse_show_cmd(args01) assert aptly_state['number of packages'] == "2"
def test_mirror_create(): """Test if createing mirrors works.""" with test.clean_and_config(os.path.join( _test_base, b"mirror-google.yml", )) as (tyml, config): args = [ '-c', config, 'mirror', 'create' ] keys_added = [] with testfixtures.LogCapture() as l: main(args) for rec in l.records: for arg in rec.args: if isinstance(arg, list): if arg[0] == "gpg": keys_added.append(arg[7]) assert len(keys_added) > 0 assert len(keys_added) == len(set(keys_added)), ( "Key multiple times added" ) expect = set(tyml['mirror'].keys()) state = SystemStateReader() state.read() assert state.mirrors == expect
def test_dependency_callback_file(): """Test if bad dependencies fail correctly.""" state = SystemStateReader() try: state.has_dependency(['turbo', 'banana']) except ValueError as e: assert "Unknown dependency" in e.args[0] error = True assert error
def do_repo_create(config): """Test if creating repositories works.""" args = ['-c', config, 'repo', 'create'] main(args) state = SystemStateReader() state.read() call_output([ 'aptly', 'repo', 'add', 'centrify', 'vagrant/hellome_0.1-1_amd64.deb' ]) assert set(['centrify']) == state.repos
def do_snapshot_create(config): """Test if createing snapshots works""" do_mirror_update(config) args = ['-c', config, 'snapshot', 'create'] main(args) state = SystemStateReader() state.read() assert set(['fakerepo01-20121010T0000Z', 'fakerepo02-20121006T0000Z']).issubset(state.snapshots) return state
def test_snapshot_create_repo(): """Test if repo snapshot create works.""" with test.clean_and_config(os.path.join( _test_base, b"snapshot_repo.yml", )) as (tyml, config): do_repo_create(config) args = ['-c', config, 'snapshot', 'create'] main(args) state = SystemStateReader() state.read() assert set(['centrify-latest']).issubset(state.snapshots) return state
def do_publish_create(config): """Test if creating publishes works.""" do_snapshot_create(config) args = ['-c', config, 'publish', 'create'] main(args) state = SystemStateReader() state.read() assert set(['fakerepo02 main', 'fakerepo01 main']) == state.publishes expect = { 'fakerepo02 main': set(['fakerepo02-20121006T0000Z']), 'fakerepo01 main': set(['fakerepo01-20121010T0000Z']) } assert expect == state.publish_map
def do_snapshot_update_rotating(config): """Helper for rotating snapshot tests""" do_mirror_update(config) args = [ '-c', config, 'snapshot', 'create', ] main(args) state = SystemStateReader() state.read() assert set( [ 'fake-current', 'fakerepo01-current', 'fakerepo02-current', ] ).issubset(state.snapshots) args = [ '-c', config, 'snapshot', 'update', ] main(args) state.read() assert set( [ 'fake-current', 'fakerepo01-current-rotated-20121010T1010Z', 'fakerepo02-current-rotated-20121010T1010Z', ] ).issubset(state.snapshots) expected = { u'fake-current': set([ u'fakerepo01-current', u'fakerepo02-current' ]), u'fake-current-rotated-20121010T1010Z': set([ u'fakerepo01-current-rotated-20121010T1010Z', u'fakerepo02-current-rotated-20121010T1010Z' ]), u'fakerepo01-current': set([]), u'fakerepo01-current-rotated-20121010T1010Z': set([]), u'fakerepo02-current': set([]), u'fakerepo02-current-rotated-20121010T1010Z': set([]), } assert state.snapshot_map == expected
def do_snapshot_create(config): """Test if createing snapshots works""" do_mirror_update(config) args = [ '-c', config, 'snapshot', 'create' ] main(args) state = SystemStateReader() state.read() assert set( ['fakerepo01-20121010T0000Z', 'fakerepo02-20121006T0000Z'] ).issubset(state.snapshots) return state
def test_repo_create_single(): """Test if creating a single repo works.""" with test.clean_and_config(os.path.join( _test_base, b"repo.yml", )) as (tyml, config): args = [ '-c', config, 'repo', 'create', 'centrify', ] main(args) state = SystemStateReader() state.read() assert set(['centrify']) == state.repos
def test_snapshot_update_twice_rotating(): """Test if rotating snapshot update works.""" with test.clean_and_config( os.path.join( _test_base, b"snapshot-current.yml", )) as (tyml, config): do_snapshot_update_rotating(config) with freezegun.freeze_time("2012-11-10 10:10:10"): args = [ '-c', config, 'snapshot', 'update', ] main(args) state = SystemStateReader() state.read() assert set([ 'fake-current', 'fakerepo01-current-rotated-20121010T1010Z', 'fakerepo02-current-rotated-20121010T1010Z', 'fakerepo01-current-rotated-20121110T1010Z', 'fakerepo02-current-rotated-20121110T1010Z', ]).issubset(state.snapshots) expected = { u'fake-current': set([u'fakerepo01-current', u'fakerepo02-current']), u'fake-current-rotated-20121010T1010Z': set([u'fakerepo01-current', u'fakerepo02-current']), u'fake-current-rotated-20121110T1010Z': set([u'fakerepo01-current', u'fakerepo02-current']), u'fakerepo01-current': set([]), u'fakerepo01-current-rotated-20121010T1010Z': set([]), u'fakerepo01-current-rotated-20121110T1010Z': set([]), u'fakerepo02-current': set([]), u'fakerepo02-current-rotated-20121010T1010Z': set([]), u'fakerepo02-current-rotated-20121110T1010Z': set([]) } assert state.snapshot_map == expected
def do_publish_create_rotating(config): """Test if creating publishes works.""" do_snapshot_update_rotating(config) args = ['-c', config, 'publish', 'create'] main(args) state = SystemStateReader() state.read() assert set([ 'fakerepo01/current stable', 'fake/current stable', 'fakerepo02/current stable', ]) == state.publishes expect = { u'fake/current stable': set([u'fake-current']), u'fakerepo01/current stable': set([u'fakerepo01-current']), u'fakerepo02/current stable': set([u'fakerepo02-current']) } assert expect == state.publish_map
def test_snapshot_create_single(): """Test if single snapshot create works.""" with test.clean_and_config(os.path.join( _test_base, b"snapshot.yml", )) as (tyml, config): do_mirror_update(config) args = [ '-c', config, 'snapshot', 'create', 'fakerepo01-%T', ] main(args) state = SystemStateReader() state.read() assert set(['fakerepo01-20121010T0000Z']).issubset(state.snapshots)
def do_repo_create(config): """Test if creating repositories works.""" args = [ '-c', config, 'repo', 'create' ] main(args) state = SystemStateReader() state.read() call_output([ 'aptly', 'repo', 'add', 'centrify', 'vagrant/hellome_0.1-1_amd64.deb' ]) assert set(['centrify']) == state.repos
def do_publish_create(config): """Test if creating publishes works.""" do_snapshot_create(config) args = [ '-c', config, 'publish', 'create' ] main(args) state = SystemStateReader() state.read() assert set( ['fakerepo02 main', 'fakerepo01 main'] ) == state.publishes expect = { 'fakerepo02 main': set(['fakerepo02-20121006T0000Z']), 'fakerepo01 main': set(['fakerepo01-20121010T0000Z']) } assert expect == state.publish_map
def test_publish_create_single(): """Test if creating a single publish works.""" with test.clean_and_config(os.path.join( _test_base, b"publish.yml", )) as (tyml, config): do_snapshot_create(config) args = [ '-c', config, 'publish', 'create', 'fakerepo01', ] main(args) state = SystemStateReader() state.read() assert set(['fakerepo01 main']) == state.publishes expect = {'fakerepo01 main': set(['fakerepo01-20121010T0000Z'])} assert expect == state.publish_map
def test_snapshot_create_single(): """Test if single snapshot create works.""" with test.clean_and_config(os.path.join( _test_base, b"snapshot.yml", )) as (tyml, config): do_mirror_update(config) args = [ '-c', config, 'snapshot', 'create', 'fakerepo01-%T', ] main(args) state = SystemStateReader() state.read() assert set( ['fakerepo01-20121010T0000Z'] ).issubset(state.snapshots)
def do_publish_create_republish(config): """Test if creating republishes works.""" with testfixtures.LogCapture() as l: do_publish_create(config) found = False for rec in l.records: if rec.levelname == "CRITICAL": if "has been deferred" in rec.msg: found = True assert found args = [ '-c', config, 'publish', 'create', ] main(args) state = SystemStateReader() state.read() assert 'fakerepo01-stable main' in state.publishes
def test_snapshot_create_repo(): """Test if repo snapshot create works.""" with test.clean_and_config(os.path.join( _test_base, b"snapshot_repo.yml", )) as (tyml, config): do_repo_create(config) args = [ '-c', config, 'snapshot', 'create' ] main(args) state = SystemStateReader() state.read() assert set( ['centrify-latest'] ).issubset(state.snapshots) return state
def test_pretend(): """Test if pretend is enabled with -p""" with test.clean_and_config(os.path.join( _test_base, b"publish.yml", )) as (tyml, config): do_snapshot_create(config) args = [ '-p', '-c', config, 'publish', 'create', 'fakerepo01', ] main(args) state = SystemStateReader() state.read() assert set() == state.publishes assert {} == state.publish_map assert Command.pretend_mode
def test_snapshot_create_rotating(): """Test if rotating snapshot create works.""" with test.clean_and_config( os.path.join( _test_base, b"snapshot-current.yml", )) as (tyml, config): do_mirror_update(config) args = [ '-c', config, 'snapshot', 'create', ] main(args) state = SystemStateReader() state.read() assert set([ 'fake-current', 'fakerepo01-current', 'fakerepo02-current', ]).issubset(state.snapshots)
def test_publish_update_republish(): """Test if update republishes works.""" with test.clean_and_config( os.path.join( _test_base, b"publish_publish.yml", )) as (tyml, config): do_publish_create_republish(config) with freezegun.freeze_time("2012-10-11 10:10:10"): args = [ '-c', config, 'snapshot', 'create', ] main(args) args = [ '-c', config, 'publish', 'update', ] main(args) state = SystemStateReader() state.read() assert 'fakerepo01-stable main' in state.publishes # As you see fakerepo01-stable main points to the old snapshot # this is theoretically not correct, but it will be fixed with # the next call to publish update. Since we use this from a hourly cron # job it is no problem. # This can't be easily fixed and would need a rewrite of the # dependencies engine. expect = { 'fakerepo01-stable main': set(['fakerepo01-20121010T0000Z']), 'fakerepo02 main': set(['fakerepo02-20121006T0000Z']), 'fakerepo01 main': set(['fakerepo01-20121011T0000Z']) } assert expect == state.publish_map
def test_snapshot_create_rotating(): """Test if rotating snapshot create works.""" with test.clean_and_config(os.path.join( _test_base, b"snapshot-current.yml", )) as (tyml, config): do_mirror_update(config) args = [ '-c', config, 'snapshot', 'create', ] main(args) state = SystemStateReader() state.read() assert set( [ 'fake-current', 'fakerepo01-current', 'fakerepo02-current', ] ).issubset(state.snapshots)
def do_publish_create_rotating(config): """Test if creating publishes works.""" do_snapshot_update_rotating(config) args = [ '-c', config, 'publish', 'create' ] main(args) state = SystemStateReader() state.read() assert set([ 'fakerepo01/current stable', 'fake/current stable', 'fakerepo02/current stable', ]) == state.publishes expect = { u'fake/current stable': set([u'fake-current']), u'fakerepo01/current stable': set([u'fakerepo01-current']), u'fakerepo02/current stable': set([u'fakerepo02-current']) } assert expect == state.publish_map
def test_publish_snapshot_update_rotating(): """Test if update rotating publishes via snapshot works.""" with test.clean_and_config(os.path.join( _test_base, b"publish-current.yml", )) as (tyml, config): do_publish_create_rotating(config) with freezegun.freeze_time("2012-10-11 10:10:10"): args = [ '-c', config, 'snapshot', 'update', ] main(args) state = SystemStateReader() state.read() expect = { u'fake/current stable': set([u'fake-current']), u'fakerepo01/current stable': set([u'fakerepo01-current']), u'fakerepo02/current stable': set([u'fakerepo02-current']) } assert expect == state.publish_map
def test_mirror_create(): """Test if createing mirrors works.""" with test.clean_and_config(os.path.join( _test_base, b"mirror-google.yml", )) as (tyml, config): args = ['-c', config, 'mirror', 'create'] keys_added = [] with testfixtures.LogCapture() as l: main(args) for rec in l.records: for arg in rec.args: if isinstance(arg, list): if arg[0] == "gpg": keys_added.append(arg[7]) assert len(keys_added) > 0 assert len(keys_added) == len( set(keys_added)), ("Key multiple times added") expect = set(tyml['mirror'].keys()) state = SystemStateReader() state.read() assert state.mirrors == expect
def test_publish_update_republish(): """Test if update republishes works.""" with test.clean_and_config(os.path.join( _test_base, b"publish_publish.yml", )) as (tyml, config): do_publish_create_republish(config) with freezegun.freeze_time("2012-10-11 10:10:10"): args = [ '-c', config, 'snapshot', 'create', ] main(args) args = [ '-c', config, 'publish', 'update', ] main(args) state = SystemStateReader() state.read() assert 'fakerepo01-stable main' in state.publishes # As you see fakerepo01-stable main points to the old snapshot # this is theoretically not correct, but it will be fixed with # the next call to publish update. Since we use this from a hourly cron # job it is no problem. # This can't be easily fixed and would need a rewrite of the # dependencies engine. expect = { 'fakerepo01-stable main': set(['fakerepo01-20121010T0000Z']), 'fakerepo02 main': set(['fakerepo02-20121006T0000Z']), 'fakerepo01 main': set(['fakerepo01-20121011T0000Z']) } assert expect == state.publish_map
def test_publish_updating_basic(): """Test if updating publishes works.""" with test.clean_and_config(os.path.join( _test_base, b"publish.yml", )) as (tyml, config): do_publish_create(config) with freezegun.freeze_time("2012-10-11 10:10:10"): args = [ '-c', config, 'snapshot', 'create' ] main(args) args = [ '-c', config, 'publish', 'update' ] main(args) state = SystemStateReader() state.read() expect = set([ 'archived-fakerepo01-20121011T1010Z', 'fakerepo01-20121011T0000Z', 'fakerepo02-20121006T0000Z', 'fakerepo01-20121010T0000Z', ]) assert expect == state.snapshots expect = { 'fakerepo02 main': set(['fakerepo02-20121006T0000Z']), 'fakerepo01 main': set(['fakerepo01-20121011T0000Z']) } assert expect == state.publish_map
def test_publish_create_single(): """Test if creating a single publish works.""" with test.clean_and_config(os.path.join( _test_base, b"publish.yml", )) as (tyml, config): do_snapshot_create(config) args = [ '-c', config, 'publish', 'create', 'fakerepo01', ] main(args) state = SystemStateReader() state.read() assert set( ['fakerepo01 main'] ) == state.publishes expect = { 'fakerepo01 main': set(['fakerepo01-20121010T0000Z']) } assert expect == state.publish_map
def test_publish_snapshot_update_rotating(): """Test if update rotating publishes via snapshot works.""" with test.clean_and_config( os.path.join( _test_base, b"publish-current.yml", )) as (tyml, config): do_publish_create_rotating(config) with freezegun.freeze_time("2012-10-11 10:10:10"): args = [ '-c', config, 'snapshot', 'update', ] main(args) state = SystemStateReader() state.read() expect = { u'fake/current stable': set([u'fake-current']), u'fakerepo01/current stable': set([u'fakerepo01-current']), u'fakerepo02/current stable': set([u'fakerepo02-current']) } assert expect == state.publish_map
def do_snapshot_update_rotating(config): """Helper for rotating snapshot tests""" do_mirror_update(config) args = [ '-c', config, 'snapshot', 'create', ] main(args) state = SystemStateReader() state.read() assert set([ 'fake-current', 'fakerepo01-current', 'fakerepo02-current', ]).issubset(state.snapshots) args = [ '-c', config, 'snapshot', 'update', ] main(args) state.read() assert set([ 'fake-current', 'fakerepo01-current-rotated-20121010T1010Z', 'fakerepo02-current-rotated-20121010T1010Z', ]).issubset(state.snapshots) expected = { u'fake-current': set([u'fakerepo01-current', u'fakerepo02-current']), u'fake-current-rotated-20121010T1010Z': set([ u'fakerepo01-current-rotated-20121010T1010Z', u'fakerepo02-current-rotated-20121010T1010Z' ]), u'fakerepo01-current': set([]), u'fakerepo01-current-rotated-20121010T1010Z': set([]), u'fakerepo02-current': set([]), u'fakerepo02-current-rotated-20121010T1010Z': set([]), } assert state.snapshot_map == expected
def do_mirror_update(config): """Test if updating mirrors works.""" args = ['-c', config, 'mirror', 'create'] state = SystemStateReader() state.read() assert "fakerepo01" not in state.mirrors main(args) state.read() assert "fakerepo01" in state.mirrors args[3] = 'update' main(args) args = [ 'aptly', 'mirror', 'show', ] args01 = list(args) args01.append("fakerepo01") aptly_state = test.execute_and_parse_show_cmd(args01) assert aptly_state['number of packages'] == "2"
def test_snapshot_update_threetimes_rotating(): """Test if rotating snapshot update works.""" with test.clean_and_config(os.path.join( _test_base, b"snapshot-current.yml", )) as (tyml, config): do_snapshot_update_rotating(config) with freezegun.freeze_time("2012-10-11 10:10:10"): args = [ '-c', config, 'snapshot', 'update', ] main(args) state = SystemStateReader() state.read() assert set( [ 'fake-current', 'fakerepo01-current-rotated-20121010T1010Z', 'fakerepo02-current-rotated-20121010T1010Z', 'fakerepo01-current-rotated-20121011T1010Z', 'fakerepo02-current-rotated-20121011T1010Z', ] ).issubset(state.snapshots) expected = { u'fake-current': set([ u'fakerepo01-current', u'fakerepo02-current' ]), u'fake-current-rotated-20121010T1010Z': set([ u'fakerepo01-current-rotated-20121010T1010Z', u'fakerepo02-current-rotated-20121010T1010Z' ]), u'fake-current-rotated-20121011T1010Z': set([ u'fakerepo01-current-rotated-20121011T1010Z', u'fakerepo02-current-rotated-20121011T1010Z', ]), u'fakerepo01-current': set([]), u'fakerepo01-current-rotated-20121010T1010Z': set([]), u'fakerepo01-current-rotated-20121011T1010Z': set([]), u'fakerepo02-current': set([]), u'fakerepo02-current-rotated-20121010T1010Z': set([]), u'fakerepo02-current-rotated-20121011T1010Z': set([]) } assert state.snapshot_map == expected with freezegun.freeze_time("2012-10-12 10:10:10"): args = [ '-c', config, 'snapshot', 'update', ] main(args) state = SystemStateReader() state.read() assert set( [ 'fake-current', 'fakerepo01-current-rotated-20121011T1010Z', 'fakerepo02-current-rotated-20121011T1010Z', 'fakerepo01-current-rotated-20121012T1010Z', 'fakerepo02-current-rotated-20121012T1010Z', ] ).issubset(state.snapshots) expected = { u'fake-current': set([ u'fakerepo01-current', u'fakerepo02-current' ]), u'fake-current-rotated-20121010T1010Z': set([ u'fakerepo01-current-rotated-20121010T1010Z', u'fakerepo02-current-rotated-20121010T1010Z' ]), u'fake-current-rotated-20121011T1010Z': set([ u'fakerepo01-current-rotated-20121011T1010Z', u'fakerepo02-current-rotated-20121011T1010Z', ]), u'fake-current-rotated-20121012T1010Z': set([ u'fakerepo01-current-rotated-20121012T1010Z', u'fakerepo02-current-rotated-20121012T1010Z', ]), u'fakerepo01-current': set([]), u'fakerepo01-current-rotated-20121010T1010Z': set([]), u'fakerepo01-current-rotated-20121011T1010Z': set([]), u'fakerepo01-current-rotated-20121012T1010Z': set([]), u'fakerepo02-current': set([]), u'fakerepo02-current-rotated-20121010T1010Z': set([]), u'fakerepo02-current-rotated-20121011T1010Z': set([]), u'fakerepo02-current-rotated-20121012T1010Z': set([]), } assert state.snapshot_map == expected