def test_get_storage_account(self): builtins = flexmock(sys.modules['__builtin__']) fake_locations_json = flexmock(name='fake_locations_json') fake_locations_json.should_receive('read').and_return( self.default_locations_content) builtins.should_call('open') (builtins.should_receive('open').with_args( AppScaleState.locations_json_location(self.default_keyname), 'r').and_return(fake_locations_json)) actual = AppScaleState.get_storage_account(self.default_keyname) expected = 'UNIT_TEST_STORAGE' self.assertEqual(expected, actual)
def test_get_group(self): builtins = flexmock(sys.modules['__builtin__']) fake_locations_json = flexmock(name='fake_locations_json') fake_locations_json.should_receive('read').and_return( self.default_locations_content) builtins.should_call('open') (builtins.should_receive('open').with_args( AppScaleState.locations_json_location(self.default_keyname), 'r').and_return(fake_locations_json)) group = AppScaleState.get_group(self.default_keyname) expected = 'sgrahamappgroup' self.assertEqual(expected, group)
def test_get_resource_group(self): builtins = flexmock(sys.modules['__builtin__']) fake_locations_json = flexmock(name='fake_locations_json') fake_locations_json.should_receive('read').and_return( self.default_locations_content) builtins.should_call('open') (builtins.should_receive('open').with_args( AppScaleState.locations_json_location(self.default_keyname), 'r').and_return(fake_locations_json)) actual = AppScaleState.get_project(self.default_keyname) expected = 'appscale-staging' self.assertEqual(expected, actual)
def test_upgrade_json_file(self): json_loc = AppScaleState.locations_json_location(self.default_keyname) yaml_loc = AppScaleState.locations_yaml_location(self.default_keyname) with open(json_loc, 'wc') as json_fh: json_fh.write(self.old_config_json) with open(yaml_loc, 'wc') as yaml_fh: yaml_fh.write(self.old_config_yaml) AppScaleState.upgrade_json_file(self.default_keyname) # JSON content should be the expected = """{"node_info": {"node_info": [{"public_ip": "172.16.10.11", "jobs": ["load_balancer", "compute", "database", "zookeeper", "taskqueue_master", "db_master", "taskqueue", "memcache", "shadow", "login"], "ssh_key": "/etc/appscale/keys/cloud1/appscale3cc1f78769994c6ab909d278ff18d0e3.key", "instance_id": "dummyappgroup-9c3dc2be-a1ca-4dca-a32a-3dd58c407031", "instance_type": "n1-standard-1", "private_ip": "10.240.0.2", "disk": null, "cloud": "cloud1"}]}, "infrastructure_info": {"infrastructure_info": {"azure_app_secret_key": "SSSSHITSASECRET", "infrastructure": "gce", "group": "sgrahamappgroup", "zone": "us-central1-a", "project": "appscale-staging", "azure_resource_group": "UNIT_TEST_RESOURCE", "azure_tenant_id": "UNIT_TEST_TENANT_ID", "azure_subscription_id": "UNIT_TEST_SUBSCRIPTION_ID", "azure_storage_account": "UNIT_TEST_STORAGE", "azure_app_id": "UNIT_TEST_APPID"}}}""" actual = "DIDNTREAD" with open(json_loc, 'r') as json_fh: actual = json_fh.read() self.assertEqual(expected, actual) # yaml file should now be gone self.assertFalse(os.path.exists(yaml_loc))
def test_locations_json_location(self): location = AppScaleState.locations_json_location(self.default_keyname) expected = os.path.join( AppScaleState.config_path(), "locations-{0}.json".format(self.default_keyname)) self.assertEqual(expected, location)