def test_find_region_when_more_than_one_is_available(self): self.switch_in_test_settings('dummy-settings-multiple-regions.yaml') try: core.find_region() self.fail("Shouldn't be able to choose a region") except core.MultipleRegionsError as e: self.assertEqual(["us-east-1", "eu-central-1"], e.regions())
def test_find_region(self): # lsh@2022-02-23: added new project to `dummy-project.yaml` with a different aws region. # this means calling `find_region` without a stack will now find multiple regions and die. #self.assertEqual(core.find_region(), "us-east-1") self.assertEqual(core.find_region("dummy1--foo"), "us-east-1") self.assertEqual( core.find_region("project-with-fastly-shield-aws-region--bar"), "eu-central-1")
def test_find_region_when_more_than_one_is_available(self): base.switch_in_test_settings([ 'src/tests/fixtures/projects/dummy-project.yaml', 'src/tests/fixtures/additional-projects/dummy-project-eu.yaml', ]) try: core.find_region() self.fail("Shouldn't be able to choose a region") except core.MultipleRegionsError as e: self.assertCountEqual(["us-east-1", "eu-central-1"], e.regions())
def test_find_region_when_more_than_one_is_available(self): try: base.switch_in_test_settings([ 'src/tests/fixtures/projects/dummy-project.yaml', 'src/tests/fixtures/additional-projects/dummy-project-eu.yaml', ]) core.find_region() self.fail("Shouldn't be able to choose a region") except core.MultipleRegionsError as e: self.assertCountEqual(["us-east-1", "eu-central-1"], e.regions()) finally: base.switch_out_test_settings()
def restart_all_running_ec2(statefile): "restarts all running ec2 instances. multiple nodes are restarted serially and failures prevent the rest of the node from being restarted" os.system("touch " + statefile) results = core.active_stack_names(core.find_region()) u1404 = [ 'api-gateway', 'journal', 'search', 'api-dummy', 'medium', ] legacy = [ 'elife-api' ] dont_do = u1404 + legacy # order not preserved do_first = [ 'master-server', 'bus', 'elife-alfred', 'elife-bot', 'iiif', ] pname = lambda stackname: core.parse_stackname(stackname)[0] todo = sorted(results, key=lambda stackname: pname(stackname) in do_first, reverse=True) todo = filter(lambda stackname: pname(stackname) not in dont_do, todo) with open(statefile, 'r') as fh: done = fh.read().split('\n') with open(statefile, 'a') as fh: LOG.info('writing state to ' + fh.name) for stackname in todo: if stackname in done: LOG.info('skipping ' + stackname) continue try: LOG.info('restarting' + stackname) # only restart instances that are currently running # this will skip ci/end2end lifecycle.restart(stackname, initial_states='running') LOG.info('done' + stackname) fh.write(stackname + "\n") fh.flush() except BaseException: LOG.exception("unhandled exception restarting %s", stackname) LOG.warn("%s is in an unknown state", stackname) get_input('pausing, any key to continue, ctrl+c to quit') print print('wrote state to', fh.name)
def server_access(): """returns True if this builder instance has access to the master server. access may be available through presence of the master-server's bootstrap user's identify file OR current user is in master server's allowed_keys list""" stackname = core.find_master(core.find_region()) public_ip = core.stack_data(stackname, ensure_single_instance=True)[0]['PublicIpAddress'] result = local('ssh -o "StrictHostKeyChecking no" %s@%s "exit"' % (config.BOOTSTRAP_USER, public_ip)) return result.return_code == 0
def find_region(stackname=None): """tries to find the region, but falls back to user input if there are multiple regions available. Uses stackname, if provided, to filter the available regions""" try: return core.find_region(stackname) except core.MultipleRegionsError as e: print("many possible regions found!") return _pick('region', e.regions())
def server_access(): """returns True if this builder instance has access to the master server. access may be available through presence of the master-server's bootstrap user's identify file OR current user is in master server's allowed_keys list""" stackname = core.find_master(core.find_region()) public_ip = core.stack_data(stackname, ensure_single_instance=True)[0]['PublicIpAddress'] result = local('ssh -o "StrictHostKeyChecking no" %s@%s "exit"' % (config.BOOTSTRAP_USER, public_ip)) return result['succeeded']
def test_find_region(self): self.assertEqual(core.find_region(), "us-east-1")
def kick(): stackname = core.find_master(core.find_region()) with core.stack_conn(stackname, user=config.BOOTSTRAP_USER): bootstrap.run_script('kick-master.sh')
def test_find_region_when_more_than_one_is_available(self): try: core.find_region() self.fail("Shouldn't be able to choose a region") except core.MultipleRegionsError as e: self.assertCountEqual(["us-east-1", "eu-central-1"], e.regions())