Ejemplo n.º 1
0
  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']))
Ejemplo n.º 2
0
  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_update_deployment(self):
        deployment = {
            'deployment_id': 'boo',
            'deployment_type': 'cluster',
            'nodes': [{
                'public_ip': 'public1',
                'jobs': ['appengine']
            }]
        }

        # When the portal returns a HTTP_NOTFOUND, the tools should raise
        # an AppScaleException.
        http_error = urllib2.HTTPError(
            'boo', RegistrationHelper.HTTP_NOTFOUND, 'bar', 'baz',
            flexmock(read=lambda: 'blarg', readline=lambda: 'blarg'))
        flexmock(urllib2).should_receive('urlopen').and_raise(http_error)
        with self.assertRaises(AppScaleException):
            RegistrationHelper.update_deployment(deployment['deployment_type'],
                                                 deployment['nodes'],
                                                 deployment['deployment_id'])

        # When the portal returns a HTTP_BADREQUEST, the tools should raise an
        # AppScaleException.
        http_error = urllib2.HTTPError(
            'boo', RegistrationHelper.HTTP_BADREQUEST, 'bar', 'baz',
            flexmock(read=lambda: 'blarg', readline=lambda: 'blarg'))
        flexmock(urllib2).should_receive('urlopen').and_raise(http_error)
        with self.assertRaises(AppScaleException):
            RegistrationHelper.update_deployment(deployment['deployment_type'],
                                                 deployment['nodes'],
                                                 deployment['deployment_id'])

        # When the POST to the server completes, the function should return a
        # dictionary with the deployment info.
        flexmock(urllib2).should_receive('urlopen')\
          .and_return(flexmock(read=lambda: json.dumps(deployment)))
        self.assertEqual(
            deployment,
            RegistrationHelper.update_deployment(deployment['deployment_type'],
                                                 deployment['nodes'],
                                                 deployment['deployment_id']))
  def test_update_deployment(self):
    deployment = {
      'deployment_id': 'boo',
      'deployment_type': 'cluster',
      'nodes': [{'public_ip': 'public1', 'jobs': ['appengine']}]
    }

    # When the portal returns a HTTP_NOTFOUND, the tools should raise
    # an AppScaleException.
    http_error = urllib2.HTTPError('boo', RegistrationHelper.HTTP_NOTFOUND,
      'bar', 'baz', flexmock(read=lambda: 'blarg', readline=lambda: 'blarg'))
    flexmock(urllib2).should_receive('urlopen').and_raise(http_error)
    with self.assertRaises(AppScaleException):
      RegistrationHelper.update_deployment(deployment['deployment_type'],
        deployment['nodes'], deployment['deployment_id'])

    # When the portal returns a HTTP_BADREQUEST, the tools should raise an
    # AppScaleException.
    http_error = urllib2.HTTPError('boo', RegistrationHelper.HTTP_BADREQUEST,
      'bar', 'baz', flexmock(read=lambda: 'blarg', readline=lambda: 'blarg'))
    flexmock(urllib2).should_receive('urlopen').and_raise(http_error)
    with self.assertRaises(AppScaleException):
      RegistrationHelper.update_deployment(deployment['deployment_type'],
        deployment['nodes'], deployment['deployment_id'])

    # When the POST to the server completes, the function should return a
    # dictionary with the deployment info.
    flexmock(urllib2).should_receive('urlopen')\
      .and_return(flexmock(read=lambda: json.dumps(deployment)))
    self.assertEqual(
      deployment,
      RegistrationHelper.update_deployment(
        deployment['deployment_type'],
        deployment['nodes'],
        deployment['deployment_id']
      )
    )