def main(): MM = utils.MetadataManager testee = MM.FetchMetadataDefault('testee') alias_ip = MM.FetchMetadataDefault('alias_ip') alias_ip_mask = MM.FetchMetadataDefault('alias_ip_mask') credentials, _ = auth.default() compute = utils.GetCompute(discovery, credentials) MD = MM(compute, testee) # Verify IP aliasing is working: not available on Windows environment if RequestOS(testee) != 'windows': # 1) Testing if it works on creation time TestIPAlias(testee, alias_ip, alias_ip_mask) # 2) Removing it and guaranteeing that it doesn't work anymore SetIPAlias(MD, testee, []) try: TestIPAlias(testee, alias_ip, alias_ip_mask) except RequestError as e: # the positive test is expected to fail, as no alias ip exists. if not e.positive_test: raise e # 3) Re-add it while the machine is running and verify that it works SetIPAlias(MD, testee, alias_ip, alias_ip_mask) TestIPAlias(testee, alias_ip, alias_ip_mask) # Ensure routes are added when ForwardingRules are created testee_fr = MM.FetchMetadataDefault('testee_forwarding_rule') TestForwardingRule(MD, testee, testee_fr)
def main(): global MD global MASTER_KEY global OSLOGIN_TESTER global OSADMINLOGIN_TESTER global TESTEE global OSLOGIN_USERS_LIB global UNIQUE_ID_USER logging.info("master: starting environment configuration") TESTEE = MM.FetchMetadataDefault('testee') OSLOGIN_TESTER = MM.FetchMetadataDefault('osLoginTester') OSADMINLOGIN_TESTER = MM.FetchMetadataDefault('osAdminLoginTester') credentials, _ = auth.default() OSLOGIN_USERS_LIB = utils.GetOslogin(discovery, credentials).users() UNIQUE_ID_USER = utils.GetServiceAccountUniqueIDUser() username = utils.GetCurrentLoginProfileUsername(OSLOGIN_USERS_LIB, UNIQUE_ID_USER) compute = utils.GetCompute(discovery, credentials) MD = MM(compute, TESTEE, username) SetEnableOsLogin(None, MM.PROJECT_LEVEL) SetEnableOsLogin(None, MM.INSTANCE_LEVEL) # Enable OsLogin in slaves md = MM(compute, OSLOGIN_TESTER, username) SetEnableOsLogin(True, MM.INSTANCE_LEVEL, md) md = MM(compute, OSADMINLOGIN_TESTER, username) SetEnableOsLogin(True, MM.INSTANCE_LEVEL, md) # Add key in Metadata and in OsLogin to allow access peers in both modes MASTER_KEY = MD.AddSshKey(MM.SSH_KEYS, MM.PROJECT_LEVEL) master_key_fingerprint = AddKeyOsLogin(MASTER_KEY + '.pub') # Execute tests try: logging.info("master: starting: TestOsLogin(MM.INSTANCE_LEVEL)") TestOsLogin(MM.INSTANCE_LEVEL) logging.info("master: starting: TestOsLogin(MM.PROJECT_LEVEL)") TestOsLogin(MM.PROJECT_LEVEL) logging.info( "master: starting: TestMetadataWithOsLogin(MM.INSTANCE_LEVEL)") TestMetadataWithOsLogin(MM.INSTANCE_LEVEL) logging.info( "master: starting: TestMetadataWithOsLogin(MM.PROJECT_LEVEL)") TestMetadataWithOsLogin(MM.PROJECT_LEVEL) logging.info("master: starting test: TestOsLoginFalseInInstance()") TestOsLoginFalseInInstance() # Clean keys finally: logging.info("master: starting environment cleanup") MD.RemoveSshKey(MASTER_KEY, MM.SSH_KEYS, MM.PROJECT_LEVEL) RemoveKeyOsLogin(master_key_fingerprint)
def main(): global MD compute = utils.GetCompute(discovery, oauth2client.client.GoogleCredentials) testee = MM.FetchMetadataDefault('testee') MD = MM(compute, testee) MD.SetMetadata('enable-oslogin', False, MM.PROJECT_LEVEL) SetBlockProjectSshKeys(False) TestLoginSshKeys(MM.INSTANCE_LEVEL) TestLoginSshKeys(MM.PROJECT_LEVEL) TestSshKeysWithSshKeys(MM.INSTANCE_LEVEL) TestSshKeysWithSshKeys(MM.PROJECT_LEVEL) TestSshKeysMixedProjectInstanceLevel() TestSshKeysIgnoresProjectLevelKeys() TestBlockProjectSshKeysIgnoresProjectLevelKeys()
def main(): global COMPUTE global ZONE global PROJECT global TESTEE COMPUTE = utils.GetCompute(discovery, GoogleCredentials) ZONE = utils.GetMetadataParam('zone') PROJECT = utils.GetMetadataParam('project') TESTEE = utils.GetMetadataParam('testee') test_login_ssh_keys(INSTANCE_LEVEL) test_login_ssh_keys(PROJECT_LEVEL) test_ssh_keys_with_sshKeys(INSTANCE_LEVEL) test_ssh_keys_with_sshKeys(PROJECT_LEVEL) test_ssh_keys_mixed_project_instance_level() test_sshKeys_ignores_project_level_keys() test_block_project_ssh_keys_ignores_project_level_keys()
def main(): global MD global MASTER_KEY global OSLOGIN_TESTER global OSADMINLOGIN_TESTER global TESTEE TESTEE = MM.FetchMetadataDefault('testee') OSLOGIN_TESTER = MM.FetchMetadataDefault('osLoginTester') OSADMINLOGIN_TESTER = MM.FetchMetadataDefault('osAdminLoginTester') username = GetCurrentUsername() compute = utils.GetCompute(discovery, oauth2client.client.GoogleCredentials) MD = MM(compute, TESTEE, username) SetEnableOsLogin(None, MM.PROJECT_LEVEL) SetEnableOsLogin(None, MM.INSTANCE_LEVEL) # Enable OsLogin in slaves md = MM(compute, OSLOGIN_TESTER, username) SetEnableOsLogin(True, MM.INSTANCE_LEVEL, md) md = MM(compute, OSADMINLOGIN_TESTER, username) SetEnableOsLogin(True, MM.INSTANCE_LEVEL, md) # Add key in Metadata and in OsLogin to allow access peers in both modes MASTER_KEY = MD.AddSshKey(MM.SSH_KEYS, MM.PROJECT_LEVEL) AddKeyOsLogin(MASTER_KEY + '.pub') # Execute tests TestOsLogin(MM.INSTANCE_LEVEL) TestOsLogin(MM.PROJECT_LEVEL) TestMetadataWithOsLogin(MM.INSTANCE_LEVEL) TestMetadataWithOsLogin(MM.PROJECT_LEVEL) TestOsLoginFalseInInstance() # Clean keys MD.RemoveSshKey(MASTER_KEY, MM.SSH_KEYS, MM.PROJECT_LEVEL) RemoveKeyOsLogin(MASTER_KEY + '.pub')