Beispiel #1
0
 def test_unbind_and_bind_instance_with_extra_path(self, LoadBalancer):
     self.storage.store_binding("inst", "app.host.com")
     self.storage.replace_binding_path("inst", "/me", "somewhere.com")
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.unbind("inst", "app.host.com")
     manager.bind("inst", "app2.host.com")
     binding_data = self.storage.find_binding("inst")
     self.assertDictEqual(
         binding_data, {
             "_id":
             "inst",
             "app_host":
             "app2.host.com",
             "paths": [{
                 "path": "/me",
                 "destination": "somewhere.com",
                 "content": None
             }, {
                 "path": "/",
                 "destination": "app2.host.com"
             }]
         })
     LoadBalancer.find.assert_called_with("inst")
     manager.consul_manager.remove_location.assert_called_with("inst", "/")
     manager.consul_manager.write_location.assert_called_with(
         "inst", "/", destination="app2.host.com")
Beispiel #2
0
 def test_unbind_and_bind_instance_with_extra_path(self, LoadBalancer, nginx):
     self.storage.store_binding('inst', 'app.host.com')
     self.storage.replace_binding_path('inst', '/me', 'somewhere.com')
     lb = LoadBalancer.find.return_value
     nginx_manager = nginx.NginxDAV.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.unbind('inst', 'app.host.com')
     manager.bind('inst', 'app2.host.com')
     binding_data = self.storage.find_binding('inst')
     self.assertDictEqual(binding_data, {
         '_id': 'inst',
         'app_host': 'app2.host.com',
         'paths': [
             {'path': '/me', 'destination': 'somewhere.com', 'content': None},
             {'path': '/', 'destination': 'app2.host.com'}
         ]
     })
     LoadBalancer.find.assert_called_with('inst')
     self.assertEqual(nginx_manager.delete_binding.call_count, 2)
     nginx_manager.delete_binding.assert_any_call(lb.hosts[0].dns_name, '/')
     nginx_manager.delete_binding.assert_any_call(lb.hosts[1].dns_name, '/')
     self.assertEqual(nginx_manager.update_binding.call_count, 2)
     nginx_manager.update_binding.assert_any_call(lb.hosts[0].dns_name, '/', 'app2.host.com')
     nginx_manager.update_binding.assert_any_call(lb.hosts[1].dns_name, '/', 'app2.host.com')
Beispiel #3
0
 def test_bind_instance_with_route(self, LoadBalancer):
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     lb.hosts[0].dns_name = "h1"
     lb.hosts[1].dns_name = "h2"
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.add_route("x", "/somewhere", "my.other.host", None)
     manager.bind("x", "apphost.com")
     binding_data = self.storage.find_binding("x")
     self.assertDictEqual(
         binding_data, {
             "_id":
             "x",
             "app_host":
             "apphost.com",
             "paths": [{
                 "path": "/somewhere",
                 "destination": "my.other.host",
                 "content": None
             }, {
                 "path": "/",
                 "destination": "apphost.com"
             }]
         })
     LoadBalancer.find.assert_called_with("x")
     manager.consul_manager.write_location.assert_any_call(
         "x", "/somewhere", destination="my.other.host", content=None)
     manager.consul_manager.write_location.assert_any_call(
         "x", "/", destination="apphost.com")
Beispiel #4
0
 def test_bind_instance_with_route(self, LoadBalancer, nginx):
     lb = LoadBalancer.find.return_value
     nginx_manager = nginx.NginxDAV.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     lb.hosts[0].dns_name = 'h1'
     lb.hosts[1].dns_name = 'h2'
     manager = Manager(self.config)
     manager.add_route('x', '/somewhere', 'my.other.host', None)
     manager.bind('x', 'apphost.com')
     binding_data = self.storage.find_binding('x')
     self.assertDictEqual(binding_data, {
         '_id': 'x',
         'app_host': 'apphost.com',
         'paths': [
             {'path': '/somewhere', 'destination': 'my.other.host', 'content': None},
             {'path': '/', 'destination': 'apphost.com'}
         ]
     })
     LoadBalancer.find.assert_called_with('x')
     nginx_manager.update_binding.assert_any_call('h1', '/', 'apphost.com')
     nginx_manager.update_binding.assert_any_call('h2', '/', 'apphost.com')
     nginx_manager.update_binding.assert_any_call(
         'h1', '/somewhere', 'my.other.host', None)
     nginx_manager.update_binding.assert_any_call(
         'h2', '/somewhere', 'my.other.host', None)
Beispiel #5
0
 def test_unbind_and_bind_instance_with_extra_path(self, LoadBalancer, nginx):
     self.storage.store_binding("inst", "app.host.com")
     self.storage.replace_binding_path("inst", "/me", "somewhere.com")
     lb = LoadBalancer.find.return_value
     nginx_manager = nginx.NginxDAV.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.unbind("inst", "app.host.com")
     manager.bind("inst", "app2.host.com")
     binding_data = self.storage.find_binding("inst")
     self.assertDictEqual(binding_data, {
         "_id": "inst",
         "app_host": "app2.host.com",
         "paths": [
             {"path": "/me", "destination": "somewhere.com", "content": None},
             {"path": "/", "destination": "app2.host.com"}
         ]
     })
     LoadBalancer.find.assert_called_with("inst")
     self.assertEqual(nginx_manager.delete_binding.call_count, 2)
     nginx_manager.delete_binding.assert_any_call(lb.hosts[0].dns_name, "/")
     nginx_manager.delete_binding.assert_any_call(lb.hosts[1].dns_name, "/")
     self.assertEqual(nginx_manager.update_binding.call_count, 2)
     nginx_manager.update_binding.assert_any_call(lb.hosts[0].dns_name, "/", "app2.host.com")
     nginx_manager.update_binding.assert_any_call(lb.hosts[1].dns_name, "/", "app2.host.com")
Beispiel #6
0
 def test_bind_instance(self, LoadBalancer):
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     lb.hosts[0].dns_name = "h1"
     lb.hosts[1].dns_name = "h2"
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.bind("x", "apphost.com")
     binding_data = self.storage.find_binding("x")
     self.assertDictEqual(binding_data, {
         "_id": "x",
         "app_host": "apphost.com",
         "paths": [{"path": "/", "destination": "apphost.com"}]
     })
     LoadBalancer.find.assert_called_with("x")
     manager.consul_manager.write_location.assert_called_with("x", "/", destination="apphost.com")
Beispiel #7
0
 def test_bind_instance(self, LoadBalancer, nginx):
     lb = LoadBalancer.find.return_value
     nginx_manager = nginx.NginxDAV.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     lb.hosts[0].dns_name = "h1"
     lb.hosts[1].dns_name = "h2"
     manager = Manager(self.config)
     manager.bind("x", "apphost.com")
     binding_data = self.storage.find_binding("x")
     self.assertDictEqual(binding_data, {
         "_id": "x",
         "app_host": "apphost.com",
         "paths": [{"path": "/", "destination": "apphost.com"}]
     })
     LoadBalancer.find.assert_called_with("x")
     nginx_manager.update_binding.assert_any_call("h1", "/", "apphost.com")
     nginx_manager.update_binding.assert_any_call("h2", "/", "apphost.com")
Beispiel #8
0
 def test_unbind_and_bind_instance_with_extra_path(self, LoadBalancer):
     self.storage.store_binding("inst", "app.host.com")
     self.storage.replace_binding_path("inst", "/me", "somewhere.com")
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.unbind("inst", "app.host.com")
     manager.bind("inst", "app2.host.com")
     binding_data = self.storage.find_binding("inst")
     self.assertDictEqual(binding_data, {
         "_id": "inst",
         "app_host": "app2.host.com",
         "paths": [
             {"path": "/me", "destination": "somewhere.com", "content": None},
             {"path": "/", "destination": "app2.host.com"}
         ]
     })
     LoadBalancer.find.assert_called_with("inst")
     manager.consul_manager.remove_location.assert_called_with("inst", "/")
     manager.consul_manager.write_location.assert_called_with("inst", "/", destination="app2.host.com")
Beispiel #9
0
 def test_bind_instance_multiple_bind_hosts(self, LoadBalancer):
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.bind("x", "apphost.com")
     binding_data = self.storage.find_binding("x")
     self.assertDictEqual(
         binding_data, {
             "_id": "x",
             "app_host": "apphost.com",
             "paths": [{
                 "path": "/",
                 "destination": "apphost.com"
             }]
         })
     LoadBalancer.find.assert_called_with("x")
     manager.consul_manager.write_location.assert_called_with(
         "x", "/", destination="apphost.com")
     manager.consul_manager.reset_mock()
     manager.bind("x", "apphost.com")
     self.assertEqual(0, len(manager.consul_manager.mock_calls))
     with self.assertRaises(rpaas.manager.BindError):
         manager.bind("x", "another.host.com")
     self.assertEqual(0, len(manager.consul_manager.mock_calls))
Beispiel #10
0
 def test_bind_instance_multiple_bind_hosts(self, LoadBalancer):
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.bind("x", "apphost.com")
     binding_data = self.storage.find_binding("x")
     self.assertDictEqual(binding_data, {
         "_id": "x",
         "app_host": "apphost.com",
         "paths": [{"path": "/", "destination": "apphost.com"}]
     })
     LoadBalancer.find.assert_called_with("x")
     manager.consul_manager.write_location.assert_called_with("x", "/", destination="apphost.com")
     manager.consul_manager.reset_mock()
     manager.bind("x", "apphost.com")
     self.assertEqual(0, len(manager.consul_manager.mock_calls))
     with self.assertRaises(rpaas.manager.BindError):
         manager.bind("x", "another.host.com")
     self.assertEqual(0, len(manager.consul_manager.mock_calls))
Beispiel #11
0
 def test_bind_instance_multiple_bind_hosts(self, LoadBalancer, nginx):
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.bind('x', 'apphost.com')
     binding_data = self.storage.find_binding('x')
     self.assertDictEqual(binding_data, {
         '_id': 'x',
         'app_host': 'apphost.com',
         'paths': [{'path': '/', 'destination': 'apphost.com'}]
     })
     LoadBalancer.find.assert_called_with('x')
     nginx_manager = nginx.NginxDAV.return_value
     nginx_manager.update_binding.assert_any_call(lb.hosts[0].dns_name, '/', 'apphost.com')
     nginx_manager.update_binding.assert_any_call(lb.hosts[1].dns_name, '/', 'apphost.com')
     nginx_manager.reset_mock()
     manager.bind('x', 'apphost.com')
     self.assertEqual(len(nginx_manager.mock_calls), 0)
     with self.assertRaises(rpaas.manager.BindError):
         manager.bind('x', 'another.host.com')
     self.assertEqual(len(nginx_manager.mock_calls), 0)
Beispiel #12
0
 def test_bind_instance_multiple_bind_hosts(self, LoadBalancer, nginx):
     lb = LoadBalancer.find.return_value
     lb.hosts = [mock.Mock(), mock.Mock()]
     manager = Manager(self.config)
     manager.bind("x", "apphost.com")
     binding_data = self.storage.find_binding("x")
     self.assertDictEqual(binding_data, {
         "_id": "x",
         "app_host": "apphost.com",
         "paths": [{"path": "/", "destination": "apphost.com"}]
     })
     LoadBalancer.find.assert_called_with("x")
     nginx_manager = nginx.NginxDAV.return_value
     nginx_manager.update_binding.assert_any_call(lb.hosts[0].dns_name, "/", "apphost.com")
     nginx_manager.update_binding.assert_any_call(lb.hosts[1].dns_name, "/", "apphost.com")
     nginx_manager.reset_mock()
     manager.bind("x", "apphost.com")
     self.assertEqual(len(nginx_manager.mock_calls), 0)
     with self.assertRaises(rpaas.manager.BindError):
         manager.bind("x", "another.host.com")
     self.assertEqual(len(nginx_manager.mock_calls), 0)
Beispiel #13
0
 def test_bind_instance_error_task_running(self):
     self.storage.store_task("x")
     manager = Manager(self.config)
     with self.assertRaises(rpaas.tasks.NotReadyError):
         manager.bind("x", "apphost.com")
Beispiel #14
0
 def test_bind_instance_error_task_running(self):
     self.storage.store_task("x")
     manager = Manager(self.config)
     with self.assertRaises(rpaas.tasks.NotReadyError):
         manager.bind("x", "apphost.com")