def setUpClass(cls): # The rule to evaluate number as boolean is inspired by C++11 implementation # All numbers but 0 and True or true will be evaluated as True cls.logging = re.search(r'^-?[1-9][0-9]*$|^[Tt]rue$', os.getenv("LOG_TO_STDOUT", "False")) != None path = os.getenv("CONFIG_YAML", DEFAULT_CONFIG_YAML) cls.account = read_yaml_file(path) cls.account["credentials"] = (lookup_values( cls.account.get("credentials_keys"))) if "resources" in cls.account: cls.resource_data = cls.account.get("resources") else: cls.resource_data = [{ "resource": cls.account.get("resource"), "expected_metrics": cls.account.get("expected_metrics") }] cls.runner = Flexer() cfg = load_config(cfg_file=CONFIG_FILE)["regions"]["default"] client = CmpClient(url=cfg["cmp_url"], auth=(cfg['cmp_api_key'], cfg['cmp_api_secret'])) cls.context = FlexerContext(cmp_client=client) secrets = (lookup_values(cls.account.get("secrets_keys"))) cls.context.secrets = secrets
def __init__(self, cmp_client=None): """Construct a new FlexerContext object.""" self.response_headers = {} self.config = {} self.secrets = {} self.state = None self.customer_id = None self.user_id = None self.user_name = "" self.region = Config.CMP_REGION self.platform = Config.CMP_PLATFORM self.version = Config.FLEXER_VERSION self.module_id = Config.MODULE_ID if cmp_client is None: auth = (Config.CMP_USERNAME, Config.CMP_PASSWORD) self.api = CmpClient(url=Config.CMP_URL, auth=auth, access_token=Config.CMP_ACCESS_TOKEN) else: self.api = cmp_client self.api_url = self.api.api_url self.api_auth = self.api.api_auth self.api_token = self.api.api_token self._db_regex = re.compile(r'mongodb://[^:]+:[^@]+@[^/]+/[^ ]+')
def cli(ctx, auth): """flexer manages your nFlex scripts from the terminal.""" cfg = ctx.config["regions"][auth] verify_ssl = ctx.config.get("verify_ssl", False) if "verify_ssl" in cfg: verify_ssl = cfg["verify_ssl"] ctx.cmp = CmpClient(url=cfg['cmp_url'], auth=(cfg['cmp_api_key'], cfg['cmp_api_secret']), verify_ssl=verify_ssl) ctx.nflex = NflexClient(ctx.cmp)
def __init__(self, cmp_client=None): """Construct a new FlexerContext object.""" self.response_headers = {} if cmp_client is None: self.api_url = Config.CMP_URL self.api_auth = (Config.CMP_USERNAME, Config.CMP_PASSWORD) self.api = CmpClient(self.api_url, self.api_auth) else: self.api_url = cmp_client._url self.api_auth = cmp_client._auth self.api = cmp_client
def setUpClass(cls): path = os.getenv("CONFIG_YAML", DEFAULT_CONFIG_YAML) cls.account = read_yaml_file(path) cls.account["credentials"] = (lookup_credentials( cls.account.get("credentials_keys"))) cls.runner = Flexer() cfg = load_config(cfg_file=CONFIG_FILE)["regions"]["default"] client = CmpClient(url=cfg["cmp_url"], auth=(cfg['cmp_api_key'], cfg['cmp_api_secret'])) cls.context = FlexerContext(cmp_client=client)
def __init__(self, cmp_client=None): """Construct a new FlexerContext object.""" self.response_headers = {} self.config = {} self.secrets = {} self.state = None self.module_id = Config.MODULE_ID if cmp_client is None: auth = (Config.CMP_USERNAME, Config.CMP_PASSWORD) self.api = CmpClient(url=Config.CMP_URL, auth=auth, access_token=Config.CMP_ACCESS_TOKEN) else: self.api = cmp_client self.api_url = self.api.api_url self.api_auth = self.api.api_auth self.api_token = self.api.api_token
def test_tasks(self, mock): auth = ('username', 'password') cmp_client = CmpClient(url='http://localhost', auth=auth, access_token='foo') task_id = 'task-1' context = FlexerContext(cmp_client=cmp_client) # Should do nothing set_task_percentage(context, None, 100) mock.post('http://localhost/tasks/task-1/update', text='null') set_task_percentage(context, task_id, 100) mock.post('http://localhost/tasks/task-1/update', text='"Oops"', status_code=500) with pytest.raises(Exception) as e: set_task_percentage(context, task_id, 100) assert 'Got bad response from tasks API' in str(e)
def __init__(self): self.credentials = load_config(CONFIG_FILE) self.cmp = CmpClient(url=self.credentials['cmp_url'], auth=(self.credentials['cmp_username'], self.credentials['cmp_password'])) self.nflex = NflexClient(self.cmp)