Exemplo n.º 1
0
 def test_bind_app_should_accept_only_post_and_delete(self):
     request = RequestFactory().get("/")
     response = BindApp.as_view()(request, "name")
     self.assertEqual(405, response.status_code)
     request = RequestFactory().put("/")
     response = BindApp.as_view()(request, "name")
     self.assertEqual(405, response.status_code)
Exemplo n.º 2
0
 def test_bind_app_in_shared_instance(self):
     settings.SHARED_SERVER = "localhost"
     instance = Instance.objects.create(
         name="inside_out",
         shared=True,
         state="running",
     )
     try:
         request = RequestFactory().post("/", {"unit-host": "192.168.1.10"})
         response = BindApp.as_view()(request, "inside_out")
         self.assertEqual(201, response.status_code)
         content = json.loads(response.content)
         expected = {
             u"MYSQL_HOST": u"localhost",
             u"MYSQL_PORT": u"3306",
             u"MYSQL_DATABASE_NAME": "inside_out",
             u"MYSQL_USER": u"inside_out",
             u"MYSQL_PASSWORD": content["MYSQL_PASSWORD"],
         }
         self.assertEqual(expected, content)
         sql = "select User, Host FROM mysql.user " +\
               "WHERE User='******' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertIsNotNone(row)
     finally:
         db = DatabaseManager("inside_out")
         db.drop_user("inside_out", "192.168.1.10")
         instance.delete()
Exemplo n.º 3
0
 def test_bind_app_creates_user(self):
     instance = Instance.objects.create(
         name="ciclops",
         host="127.0.0.1",
         ec2_id="i-009",
         state="running",
     )
     try:
         request = RequestFactory().post("/", {"unit-host": "192.168.1.1"})
         response = BindApp.as_view()(request, "ciclops")
         self.assertEqual(201, response.status_code)
         content = json.loads(response.content)
         expected = {
             u"MYSQL_HOST": u"127.0.0.1",
             u"MYSQL_PORT": u"3306",
             u"MYSQL_DATABASE_NAME": "ciclops",
             u"MYSQL_USER": u"ciclops",
             u"MYSQL_PASSWORD": content["MYSQL_PASSWORD"],
         }
         self.assertEqual(expected, content)
         sql = "select User, Host FROM mysql.user " +\
               "WHERE User='******' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertEqual("ciclops", row[0])
     finally:
         db = DatabaseManager("ciclops")
         db.drop_user("ciclops", "192.168.1.1")
         instance.delete()
Exemplo n.º 4
0
 def test_unbind_app_should_return_500_and_error_msg_in_body(self):
     instance = Instance.objects.create(name="fails", host="127.0.0.1")
     try:
         request = RequestFactory().delete("/")
         response = BindApp.as_view()(request, "fails")
         self.assertEqual(500, response.status_code)
         content = "Operation DROP USER failed for 'fails'@'%'"
         self.assertEqual(content, response.content)
     finally:
         instance.delete()
Exemplo n.º 5
0
 def test_bind_app_canonicalizes_database_name(self):
     instance = Instance.objects.create(
         name=canonicalize_db_name("some-db"),
         shared=True,
         state="running",
     )
     settings.SHARED_SERVER = "localhost"
     request = RequestFactory().post("/", {"unit-host": "someurl.com"})
     response = BindApp.as_view()(request, "some-db")
     instance.delete()
     self.assertEqual(201, response.status_code)
Exemplo n.º 6
0
 def test_bind_app_gives_precondition_failed_for_pending_instances(self):
     instance = Instance.objects.create(
         name="morning_on_earth",
         host="127.0.0.1",
         ec2_id="i-009",
         state="pending",
     )
     try:
         request = RequestFactory().post("/", {"unit-host": "192.168.1.1"})
         response = BindApp.as_view()(request, "morning_on_earth")
         self.assertEqual(412, response.status_code)
         msg = u"You can't bind to this instance because it's not running."
         self.assertEqual(msg, response.content)
     finally:
         instance.delete()
Exemplo n.º 7
0
 def test_unbind_app_drops_the_user_on_shared_instance(self):
     settings.SHARED_SERVER = "127.0.0.1"
     instance = Instance.objects.create(name="used", shared=True)
     try:
         db = DatabaseManager("used")
         db.create_user("used", "127.0.0.1")
         request = RequestFactory().delete("/used")
         response = BindApp.as_view()(request, "used")
         self.assertEqual(200, response.status_code)
         sql = "select User, Host FROM mysql.user " +\
               "WHERE User='******' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertIsNone(row)
     finally:
         instance.delete()
Exemplo n.º 8
0
    def test_unbind_app_drops_the_user(self):
        instance = Instance.objects.create(name="ciclops", host="127.0.0.1")
        try:
            db = DatabaseManager("ciclops")
            db.create_user("ciclops", "localhost")

            request = RequestFactory().delete("/ciclops")
            response = BindApp.as_view()(request, "ciclops")
            self.assertEqual(200, response.status_code)

            sql = "select User, Host FROM mysql.user " +\
                  "WHERE User='******' AND Host='%'"
            self.cursor.execute(sql)
            row = self.cursor.fetchone()
            self.assertFalse(row)
        finally:
            instance.delete()
Exemplo n.º 9
0
# Copyright 2014 mysqlapi authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from django.conf.urls import patterns, url

from mysqlapi.api.decorators import basic_auth_required
from mysqlapi.api.views import (BindApp, BindUnit, CreateDatabase,
                                DropDatabase, Healthcheck)

urlpatterns = patterns(
    '',
    url(r'^resources$', basic_auth_required(CreateDatabase.as_view())),
    url(r'^resources/(?P<name>[\w-]+)$',
        basic_auth_required(DropDatabase.as_view())),
    url(r'^resources/(?P<name>[\w-]+)/bind$',
        basic_auth_required(BindUnit.as_view())),
    url(r'^resources/(?P<name>[\w-]+)/bind-app$',
        basic_auth_required(BindApp.as_view())),
    url(r'^resources/(?P<name>[\w-]+)/export$', 'mysqlapi.api.views.export'),
    url(r'^resources/(?P<name>[\w-]+)/status$',
        basic_auth_required(Healthcheck.as_view())),
)
Exemplo n.º 10
0
 def test_unbind_app_return_404_if_the_instance_does_not_exist(self):
     request = RequestFactory().delete("/ciclops")
     response = BindApp.as_view()(request, "ciclops")
     self.assertEqual(404, response.status_code)
     self.assertEqual("Instance not found.", response.content)
Exemplo n.º 11
0
 def test_bind_app_returns_404_if_the_instance_does_not_exist(self):
     request = RequestFactory().post("/", {"unit-host": "12.12.12.12"})
     response = BindApp.as_view()(request, "idioglossia")
     self.assertEqual(404, response.status_code)
     self.assertEqual("Instance not found", response.content)
Exemplo n.º 12
0
# Copyright 2014 mysqlapi authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from django.conf.urls import patterns, url

from mysqlapi.api.decorators import basic_auth_required
from mysqlapi.api.views import (BindApp, BindUnit, CreateDatabase,
                                DropDatabase, Healthcheck)

urlpatterns = patterns('',
                       url(r'^resources$',
                           basic_auth_required(CreateDatabase.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)$',
                           basic_auth_required(DropDatabase.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)/bind$',
                           basic_auth_required(BindUnit.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)/bind-app$',
                           basic_auth_required(BindApp.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)/export$',
                           'mysqlapi.api.views.export'),
                       url(r'^resources/(?P<name>[\w-]+)/status$',
                           basic_auth_required(Healthcheck.as_view())),
                       )