Ejemplo n.º 1
0
    def test_view(self):
        """
        test getting one server
        """
        clear_db()
        s1 = Server.create(server_id=None, tenant_id=1, name="name1", status="ready")
        Server.create(server_id=None, tenant_id=1, name="name2", status="scheduled")
        Server.create(server_id=None, tenant_id=2, name="name3", status="ready")

        request = HTTPRequest(
            self.get_url("/1/servers/" + str(s1.server_id)),
            method="GET",
            headers=HTTPHeaders({"X-AUTH-TOKEN": X_AUTH_TOKEN}),
        )

        self.http_client.fetch(request, self.stop)
        response = self.wait()
        message = json.loads(response.body)

        assert message == {
            "status": s1.status,
            "id": s1.server_id,
            "name": s1.name,
            "date_created": str(s1.date_created),
        }
Ejemplo n.º 2
0
 def post(self):
     try:
         form = ServerPropertiesForm(formdata=self.request.POST)
         if form.validate():
             server = Server.create(
                 name=form.name.data,
                 is_gce=True,
                 version=form.version.data,
                 memory=form.memory.data,
                 operator=form.operator.data or None,
                 idle_timeout=form.idle_timeout.data
             )
             mc_properties = server.mc_properties
             for prop in form:
                 if prop.name not in ['name', 'version', 'memory', 'operator', 'idle_timeout']:
                     if prop.type == 'IntegerField' or prop.name in [
                         'gamemode', 'difficulty', 'op_permission_level'
                     ]:
                         if prop.data is not None:
                             setattr(mc_properties, prop.name, int(prop.data))
                     else:
                         setattr(mc_properties, prop.name, prop.data)
             mc_properties.put()
             if not set_form_short_name(server, form):
                 message = "Short name '{0}' is already assigned to another world".format(form.short_name.data)
                 self.session.add_flash(message, level='warn')
             self.redirect(webapp2.uri_for('home', server_key=server.url_key))
     except Exception, e:
         logging.error(u"Error POSTing GCE server: {0}".format(e))
         self.abort(404)
Ejemplo n.º 3
0
 def _add_server(self):
     """
     Add the current server to the table of servers
     The server_is_new flag will also be set for this session
     :return: None
     """
     self.server = Server.create(name=self.config.server_name)
     self.server_is_new = True
Ejemplo n.º 4
0
 def post(self):
     try:
         form = ServerForm(formdata=self.request.POST)
         if form.validate():
             server = Server.create(name=form.name.data, is_gce=False)
             if not set_form_short_name(server, form):
                 message = "Short name '{0}' is already assigned to another world".format(form.short_name.data)
                 self.session.add_flash(message, level='warn')
             self.redirect(webapp2.uri_for('home', server_key=server.url_key))
     except Exception, e:
         logging.error(u"Error POSTing server: {0}".format(e))
         self.abort(404)
Ejemplo n.º 5
0
    def test_list(self):
        """
        list of servers
        """
        clear_db()
        s1 = Server.create(server_id=None, tenant_id=1, name="name1", status="ready")
        s2 = Server.create(server_id=None, tenant_id=1, name="name2", status="scheduled")
        Server.create(server_id=None, tenant_id=2, name="name3", status="ready")

        request = HTTPRequest(
            self.get_url("/1/servers/"), method="GET", headers=HTTPHeaders({"X-AUTH-TOKEN": X_AUTH_TOKEN})
        )

        self.http_client.fetch(request, self.stop)
        response = self.wait()
        message = json.loads(response.body)

        assert message == {
            "servers": [
                {"status": s1.status, "id": s1.server_id, "name": s1.name},
                {"status": s2.status, "id": s2.server_id, "name": s2.name},
            ]
        }
Ejemplo n.º 6
0
    def test_delete(self):
        """
        delete existing server
        """
        clear_db()
        s1 = Server.create(server_id=None, tenant_id=1, name="name1", status="ready")

        request = HTTPRequest(
            self.get_url("/1/servers/" + str(s1.server_id)),
            method="DELETE",
            headers=HTTPHeaders({"X-AUTH-TOKEN": X_AUTH_TOKEN}),
        )

        self.http_client.fetch(request, self.stop)
        response = self.wait()
        message = json.loads(response.body)
        assert message == {"status": "deleted", "id": s1.server_id}
Ejemplo n.º 7
0
    def post(self, tenant_id):
        name = self.get_argument('name')
        if not 20 >= len(name) >= 5:
            self.write({'status': 'invalid_name'})
            return

        server = Server.create(
            server_id=None,
            tenant_id=tenant_id,
            name=name,
        )

        IOLoop.current().spawn_callback(self.run_task, server.server_id)

        self.write({
            'id': server.server_id,
            'name': server.name,
            'status': server.status,
        })
Ejemplo n.º 8
0
 def post(self):
     server = Server.create(name=self.request.form.name.data, is_gce=self.request.form.gce.data)
     self.json_response(server, SERVER_STRATEGY, status_code=201)
Ejemplo n.º 9
0
 def setUp(self):
     super(MainBaseTest, self).setUp()
     self.server = Server.create()
Ejemplo n.º 10
0
 def test_get_multi_server(self):
     Server.create()
     self.log_in_user()
     response = self.get()
     self.assertOK(response)
Ejemplo n.º 11
0
 def test_get_multi_server(self):
     Server.create()
     self.log_in_user()
     response = self.get()
     self.assertRedirects(response, to='/')
Ejemplo n.º 12
0
    server_details = result['server']
    server_id = server_details['id']

    server_query = Server.select().where(Server.st_id == server_id)
    if len(server_query) == 0:
        server_params = {'st_id': server_id,
                         'name': server_details['name'],
                         'sponsor': server_details.get('sponsor'),
                         'url': server_details.get('url'),
                         'url1': server_details.get('url2'),
                         'cc': server_details.get('cc'),
                         'host': server_details.get('host'),
                         'lat': server_details.get('lat'),
                         'lon': server_details.get('lon')}

        server = Server.create(**server_params)
        server.save()
    else:
        server = server_query[0]

    r_params = {'server': server,
                'timestamp': result['timestamp'],
                'download_spd': result.get('download'),
                'upload_spd': result.get('upload'),
                'bytes_sent': result.get('bytes_sent'),
                'bytes_rec': result.get('bytes_received'),
                'latency': result['ping'],
                'client': result['client'].get('ip')}

    r = Result(**r_params)
    r.save()
Ejemplo n.º 13
0
 def setUp(self):
     super(MainBaseTest, self).setUp()
     self.server = Server.create()