def test_services_one_group(self): """Does services("fixtures") return only the services in that group?""" sr = EFServiceRegistry( service_registry_file="test_data/test_service_registry_1.json") self.assertEqual(len(sr.services("fixtures")), 0) self.assertEqual(len(sr.services("application_services")), 1) self.assertEqual(len(sr.services("platform_services")), 2)
def test_valid_envs(self): """Does valid_envs return correct envs?""" sr = EFServiceRegistry(service_registry_file="test_data/test_service_registry_1.json") self.assertIn("proto0",sr.valid_envs("test-instance")) self.assertIn("staging",sr.valid_envs("test-instance")) self.assertIn("mgmt.ellationeng",sr.valid_envs("test-instance")) self.assertNotIn("mgmt.ellation",sr.valid_envs("test-instance"))
def test_services_one_group(self): """Does services("fixtures") return only the services in that group?""" sr = EFServiceRegistry( service_registry_file=self.service_registry_file) self.assertEqual(len(sr.services("fixtures")), 2) self.assertEqual(len(sr.services("application_services")), 1) self.assertEqual(len(sr.services("platform_services")), 3) self.assertEqual(len(sr.services("internal_services")), 1)
def test_valid_envs(self): """Does valid_envs return correct envs?""" sr = EFServiceRegistry( service_registry_file=self.service_registry_file) self.assertIn("alpha0", sr.valid_envs("test-instance")) self.assertIn("staging", sr.valid_envs("test-instance")) self.assertIn("mgmt.ellationeng", sr.valid_envs("test-instance")) self.assertNotIn("mgmt.ellation", sr.valid_envs("test-instance"))
def test_sr_loads(self, mock_check_output): """Can the default SR be loaded? (requires a default SR)""" mock_check_output.side_effect = [ os.path.join(os.path.dirname(__file__), '../test_data') ] EFConfig.DEFAULT_SERVICE_REGISTRY_FILE = "test_service_registry_1.json" sr = EFServiceRegistry()
def handle_args_and_set_context(args): """ Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated EFContext object Raises: IOError: if service registry file can't be found or can't be opened RuntimeError: if repo or branch isn't as spec'd in ef_config.EF_REPO and ef_config.EF_REPO_BRANCH CalledProcessError: if 'git rev-parse' command to find repo root could not be run """ parser = argparse.ArgumentParser() parser.add_argument("env", help=", ".join(EFConfig.ENV_LIST)) parser.add_argument("--sr", help="optional /path/to/service_registry_file.json", default=None) parser.add_argument("--commit", help="Make changes in AWS (dry run if omitted)", action="store_true", default=False) parser.add_argument("--verbose", help="Print additional info", action="store_true", default=False) parser.add_argument("--devel", help="Allow running from branch; don't refresh from origin", action="store_true", default=False) parsed_args = vars(parser.parse_args(args)) context = EFContext() context.commit = parsed_args["commit"] context.devel = parsed_args["devel"] try: context.env = parsed_args["env"] except ValueError as e: fail("Error in env: {}".format(e.message)) # Set up service registry and policy template path which depends on it context.service_registry = EFServiceRegistry(parsed_args["sr"]) context.policy_template_path = normpath(dirname(context.service_registry.filespec)) + EFConfig.POLICY_TEMPLATE_PATH_SUFFIX context.verbose = parsed_args["verbose"] return context
def handle_args_and_set_context(args): """ Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated EFCFContext object (extends EFContext) Raises: IOError: if service registry file can't be found or can't be opened RuntimeError: if repo or branch isn't as spec'd in ef_config.EF_REPO and ef_config.EF_REPO_BRANCH CalledProcessError: if 'git rev-parse' command to find repo root could not be run """ parser = argparse.ArgumentParser() parser.add_argument("template_file", help="/path/to/template_file.json") parser.add_argument("env", help=", ".join(EFConfig.ENV_LIST)) parser.add_argument( "--changeset", help="create a changeset; cannot be combined with --commit", action="store_true", default=False) parser.add_argument( "--commit", help= "Make changes in AWS (dry run if omitted); cannot be combined with --changeset", action="store_true", default=False) parser.add_argument( "--poll", help="Poll Cloudformation to check status of stack creation/updates", action="store_true", default=False) parser.add_argument("--sr", help="optional /path/to/service_registry_file.json", default=None) parser.add_argument("--verbose", help="Print additional info + resolved template", action="store_true", default=False) parser.add_argument( "--devel", help="Allow running from branch; don't refresh from origin", action="store_true", default=False) parsed_args = vars(parser.parse_args(args)) context = EFCFContext() try: context.env = parsed_args["env"] context.template_file = parsed_args["template_file"] except ValueError as e: fail("Error in argument: {}".format(e.message)) context.changeset = parsed_args["changeset"] context.commit = parsed_args["commit"] context.devel = parsed_args["devel"] context.poll_status = parsed_args["poll"] context.verbose = parsed_args["verbose"] # Set up service registry and policy template path which depends on it context.service_registry = EFServiceRegistry(parsed_args["sr"]) return context
def handle_args_and_set_context(args): """ Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated EFVersionContext object """ parser = argparse.ArgumentParser() parser.add_argument("service_name", help="name of the service") parser.add_argument("key", help="version key to look up for <service_name> such as 'ami-id' (list in EF_Config)") parser.add_argument("env", help=", ".join(EFConfig.ENV_LIST)) group = parser.add_mutually_exclusive_group(required=True) group.add_argument("--get", help="get current version", action="store_true") group.add_argument("--set", help="set current version of <key> to <value> for <service_name>") group.add_argument("--rollback", help="set current version to most recent 'stable' version in history", action="store_true") group.add_argument("--history", help="Show version history for env/service/key", choices=['json', 'text']) group.add_argument("--show", help="Show keys and values. '*' allowed for <key> and <env>", action="store_true", default=False) parser.add_argument("--build", help="On --set, also set the externally defined build number associated with the version entity", default="") parser.add_argument("--commit_hash", help="On --set, also set the commit hash associated with the version entity", default="") parser.add_argument("--commit", help="Actually --set or --rollback (dry run if omitted)", action="store_true", default=False) parser.add_argument("--devel", help="Allow running from branch; don't refresh from origin", action="store_true", default=False) parser.add_argument("--force_env_full", help="Override env with env_full for account-scoped environments", action="store_true", default=False) parser.add_argument("--limit", help="Limit 'history', 'rollback', 'show' to first N records (default 100, max 1000)", type=int, default=100) parser.add_argument("--location", help="On --set, also mark the url location of the static build's version file to" "support dist-hash precheck", default="") if EFConfig.ALLOW_EF_VERSION_SKIP_PRECHECK: parser.add_argument("--noprecheck", help="--set or --rollback without precheck", action="store_true", default=False) parser.add_argument("--sr", help="optional /path/to/service_registry_file.json", default=None) parser.add_argument("--stable", help="On --set, also mark the version 'stable'", action="store_true") parser.add_argument("--verbose", help="Print additional info", action="store_true", default=False) # parse parsed_args = vars(parser.parse_args(args)) context = EFVersionContext() # marshall the inherited context values context._build_number = parsed_args["build"] context._commit_hash = parsed_args["commit_hash"] context.commit = parsed_args["commit"] context.devel = parsed_args["devel"] context._force_env_full = parsed_args["force_env_full"] try: context.env = parsed_args["env"] except ValueError as e: fail("Error in env: {}".format(e.message)) # marshall this module's additional context values context._get = parsed_args["get"] context._history = parsed_args["history"] context._key = parsed_args["key"] if EFConfig.ALLOW_EF_VERSION_SKIP_PRECHECK: context._noprecheck = parsed_args["noprecheck"] if not 1 <= parsed_args["limit"] <= 1000: fail("Error in --limit. Valid range: 1..1000") context._limit = parsed_args["limit"] context._location = parsed_args["location"] context._rollback = parsed_args["rollback"] context._service_name = parsed_args["service_name"] context._show = parsed_args["show"] context._stable = parsed_args["stable"] context._value = parsed_args["set"] # Set up service registry and policy template path which depends on it context.service_registry = EFServiceRegistry(parsed_args["sr"]) # VERBOSE is global global VERBOSE VERBOSE = parsed_args["verbose"] validate_context(context) return context
def test_service_group(self): """Does the lookup for the group of a single service work?""" sr = EFServiceRegistry( service_registry_file="test_data/test_service_registry_1.json") self.assertRegexpMatches(sr.service_group("test-instance-2"), "^platform_services$")
def test_services(self): """Does services() return all the services?""" sr = EFServiceRegistry( service_registry_file="test_data/test_service_registry_1.json") self.assertEqual(len(sr.services()), 4)
def test_sr_loads(self): """Can the default SR be loaded? (requires a default SR)""" sr = EFServiceRegistry()
def test_service_region_override_negative(self): """Does the lookup for the wrong region that was specified of a single service fail?""" sr = EFServiceRegistry( service_registry_file=self.service_registry_file) self.assertNotRegexpMatches(sr.service_region("test-instance-3"), "^us-west-2$")
def test_service_region_override(self): """Does the lookup for the region that was specified of a single service work?""" sr = EFServiceRegistry( service_registry_file=self.service_registry_file) self.assertRegexpMatches(sr.service_region("test-instance-3"), "^us-east-1$")
def test_services(self): """Does services() return all the services?""" sr = EFServiceRegistry( service_registry_file=self.service_registry_file) self.assertEqual(len(sr.services()), 7)