def register(self, deployment_id): """ Allows users to register their AppScale deployment with the AppScale Portal. Raises: AppScaleException: If the deployment has already been registered. """ appscale_yaml = yaml.safe_load(self.read_appscalefile()) if 'keyname' in appscale_yaml: keyname = appscale_yaml['keyname'] else: keyname = 'appscale' nodes = self.get_nodes(keyname) head_node = self.get_head_node(nodes) if RegistrationHelper.appscale_has_deployment_id(head_node, keyname): existing_id = RegistrationHelper.get_deployment_id(head_node, keyname) if existing_id != deployment_id: raise AppScaleException( 'This deployment has already been registered with a different ID.') if 'infrastructure' in appscale_yaml: deployment_type = 'cloud' else: deployment_type = 'cluster' deployment = RegistrationHelper.update_deployment(deployment_type, nodes, deployment_id) RegistrationHelper.set_deployment_id(head_node, keyname, deployment_id) AppScaleLogger.success( 'Registration complete for AppScale deployment {0}.' .format(deployment['name']))
def test_appscale_has_deployment_id(self): head_node = 'boo' keyname = 'bar' flexmock(LocalState).should_receive('get_secret_key').and_return('baz') # When the AppControllerClient returns True, the function should # return True. flexmock(AppControllerClient).should_receive('deployment_id_exists')\ .and_return(True) self.assertEqual( RegistrationHelper.appscale_has_deployment_id(head_node, keyname), True) # When the AppControllerClient returns False, the function should # return False. flexmock(AppControllerClient).should_receive('deployment_id_exists')\ .and_return(False) self.assertEqual( RegistrationHelper.appscale_has_deployment_id(head_node, keyname), False)