def setup_flask_app(): global security_config if not security_config: conf_file_str = read_manager_file('/opt/manager/rest-security.conf') security_config = yaml.load(conf_file_str) manager_ip = utils.get_manager_ip() return _setup_flask_app(manager_ip=manager_ip, hash_salt=security_config['hash_salt'], secret_key=security_config['secret_key'])
def test_provider_context(self): # Context is already setup during test bootstrap phase, # we only verify everything was properly saved and accessible name = PROVIDER_NAME context = copy.deepcopy(PROVIDER_CONTEXT) context['cloudify']['cloudify_agent']['networks']['default'] = \ get_manager_ip() response_context = self.client.manager.get_context() self.assertEqual(name, response_context['name']) self.assertEqual(context, response_context['context']) self.assertRaises(CloudifyClientError, self.client.manager.create_context, name, context)
def test_provider_context(self): # Context is already setup during test bootstrap phase, # we only verify everything was properly saved and accessible name = PROVIDER_NAME context = copy.deepcopy(PROVIDER_CONTEXT) context['cloudify']['cloudify_agent']['networks']['default'] = \ get_manager_ip() response_context = self.client.manager.get_context() self.assertEqual(name, response_context['name']) self.assertEqual(context, response_context['context']) self.assertRaises(CloudifyClientError, self.client.manager.create_context, name, context)
def prepare_reset_storage_script(): reset_script = get_resource('scripts/reset_storage.py') copy_file_to_manager(reset_script, SCRIPT_PATH) with tempfile.NamedTemporaryFile(delete=False) as f: json.dump( { 'config': { '': constants.CONFIG_FILE_LOCATION, 'security': SECURITY_FILE_LOCATION, 'authorization': constants.AUTHORIZATION_FILE_LOCATION }, 'ip': utils.get_manager_ip(), 'username': utils.get_manager_username(), 'password': utils.get_manager_password(), 'provider_context': PROVIDER_CONTEXT }, f) try: copy_file_to_manager(f.name, CONFIG_PATH) finally: os.unlink(f.name)
def run_query(query, db_name=None): conf = get_postgres_conf() manager_ip = utils.get_manager_ip() db_name = db_name or conf.db_name with psycopg2.connect(database=db_name, user=conf.username, password=conf.password, host=manager_ip) as con: con.autocommit = True logger.info('Trying to execute SQL query: ' + query) with closing(con.cursor()) as cur: try: cur.execute(query) fetchall = cur.fetchall() status_message = 'ok' except Exception, e: fetchall = None status_message = str(e) return {'status': status_message, 'all': fetchall}