コード例 #1
0
 def test_new_instance_with_plan(self, nginx):
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.consul_manager.generate_token.return_value = "abc-123"
     manager.new_instance("x", plan_name="small")
     host = self.Host.create.return_value
     config = copy.deepcopy(self.config)
     config.update(self.plan["config"])
     config[
         "HOST_TAGS"] = "rpaas_service:test-suite-rpaas,rpaas_instance:x,consul_token:abc-123"
     lb = self.LoadBalancer.create.return_value
     self.Host.create.assert_called_with("my-host-manager", "x", config)
     self.LoadBalancer.create.assert_called_with("my-lb-manager", "x",
                                                 config)
     lb.add_host.assert_called_with(host)
     self.assertEquals(manager.storage.find_task("x").count(), 0)
     nginx.Nginx.assert_called_once_with(config)
     nginx_manager = nginx.Nginx.return_value
     nginx_manager.wait_healthcheck.assert_called_once_with(host.dns_name,
                                                            timeout=600)
     metadata = manager.storage.find_instance_metadata("x")
     self.assertEqual(
         {
             "_id": "x",
             "plan_name": "small",
             "consul_token": "abc-123"
         }, metadata)
コード例 #2
0
ファイル: test_manager.py プロジェクト: carriercomm/rpaas
 def test_new_instance(self, nginx):
     manager = Manager(self.config)
     manager.new_instance('x')
     host = self.Host.create.return_value
     lb = self.LoadBalancer.create.return_value
     self.Host.create.assert_called_with('my-host-manager', 'x', self.config)
     self.LoadBalancer.create.assert_called_with('my-lb-manager', 'x', self.config)
     lb.add_host.assert_called_with(host)
     self.assertIsNone(self.storage.find_task('x'))
     nginx.NginxDAV.assert_called_once_with(self.config)
     nginx_manager = nginx.NginxDAV.return_value
     nginx_manager.wait_healthcheck.assert_called_once_with(host.dns_name, timeout=600)
コード例 #3
0
 def test_new_instance_host_create_fail_and_raises(self, nginx):
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.consul_manager.generate_token.return_value = "abc-123"
     lb = self.LoadBalancer.create.return_value
     self.Host.create.side_effect = Exception("Host create failure")
     host = self.Host.create.return_value
     manager.new_instance("x")
     lb.add_host.assert_not_called()
     lb.destroy.assert_not_called()
     host.destroy.assert_not_called()
     self.assertEqual(self.storage.find_task("x").count(), 0)
コード例 #4
0
 def test_new_instance_lb_create_fail_and_rollback(self, nginx):
     config = copy.deepcopy(self.config)
     config["RPAAS_ROLLBACK_ON_ERROR"] = "1"
     manager = Manager(config)
     manager.consul_manager = mock.Mock()
     manager.consul_manager.generate_token.return_value = "abc-123"
     self.LoadBalancer.create.side_effect = Exception("LB create failure")
     lb = self.LoadBalancer.create.return_value
     host = self.Host.create.return_value
     manager.new_instance("x")
     lb.add_host.assert_not_called()
     lb.destroy.assert_not_called()
     host.destroy.assert_called_once()
     self.assertEqual(self.storage.find_task("x").count(), 0)
コード例 #5
0
 def test_new_instance(self, nginx):
     manager = Manager(self.config)
     manager.new_instance("x")
     host = self.Host.create.return_value
     lb = self.LoadBalancer.create.return_value
     config = copy.deepcopy(self.config)
     config["HOST_TAGS"] = "rpaas_service:test-suite-rpaas,rpaas_instance:x"
     self.Host.create.assert_called_with("my-host-manager", "x", config)
     self.LoadBalancer.create.assert_called_with("my-lb-manager", "x", config)
     lb.add_host.assert_called_with(host)
     self.assertIsNone(self.storage.find_task("x"))
     nginx.NginxDAV.assert_called_once_with(config)
     nginx_manager = nginx.NginxDAV.return_value
     nginx_manager.wait_healthcheck.assert_called_once_with(host.dns_name, timeout=600)
コード例 #6
0
ファイル: test_manager.py プロジェクト: ricobl/rpaas
 def test_new_instance(self, nginx):
     manager = Manager(self.config)
     manager.consul_manager = mock.Mock()
     manager.consul_manager.generate_token.return_value = "abc-123"
     manager.new_instance("x")
     host = self.Host.create.return_value
     lb = self.LoadBalancer.create.return_value
     config = copy.deepcopy(self.config)
     config["HOST_TAGS"] = "rpaas_service:test-suite-rpaas,rpaas_instance:x,consul_token:abc-123"
     self.Host.create.assert_called_with("my-host-manager", "x", config)
     self.LoadBalancer.create.assert_called_with("my-lb-manager", "x", config)
     lb.add_host.assert_called_with(host)
     self.assertEquals(self.storage.find_task("x").count(), 0)
     nginx.Nginx.assert_called_once_with(config)
     nginx_manager = nginx.Nginx.return_value
     nginx_manager.wait_healthcheck.assert_called_once_with(host.dns_name, timeout=600)
     manager.consul_manager.write_healthcheck.assert_called_once_with("x")
コード例 #7
0
ファイル: test_manager.py プロジェクト: carriercomm/rpaas
 def test_remove_instance_decrement_quota(self, nginx):
     manager = Manager(self.config)
     for name in ['a', 'b', 'c', 'd', 'e']:
         manager.new_instance(name)
     with self.assertRaises(QuotaExceededError):
         manager.new_instance('f')
     manager.remove_instance('e')
     manager.new_instance('f')
     manager.remove_instance('e')
     with self.assertRaises(QuotaExceededError):
         manager.new_instance('g')
コード例 #8
0
ファイル: test_manager.py プロジェクト: ricobl/rpaas
 def test_remove_instance_decrement_quota(self, nginx):
     manager = Manager(self.config)
     for name in ["a", "b", "c", "d", "e"]:
         manager.new_instance(name)
     with self.assertRaises(QuotaExceededError):
         manager.new_instance("f")
     manager.remove_instance("e")
     manager.new_instance("f")
     manager.remove_instance("e")
     with self.assertRaises(QuotaExceededError):
         manager.new_instance("g")
コード例 #9
0
 def test_remove_instance_decrement_quota(self, nginx):
     manager = Manager(self.config)
     for name in ["a", "b", "c", "d", "e"]:
         manager.new_instance(name)
     with self.assertRaises(QuotaExceededError):
         manager.new_instance("f")
     manager.remove_instance("e")
     manager.new_instance("f")
     manager.remove_instance("e")
     with self.assertRaises(QuotaExceededError):
         manager.new_instance("g")
コード例 #10
0
 def test_new_instance_nginx_wait_healthcheck_fail_and_rollback(
         self, nginx, hc):
     config = copy.deepcopy(self.config)
     config["RPAAS_ROLLBACK_ON_ERROR"] = "1"
     manager = Manager(config)
     manager.consul_manager = mock.Mock()
     manager.consul_manager.generate_token.return_value = "abc-123"
     lb = self.LoadBalancer.create.return_value
     host = self.Host.create.return_value
     dumb_hc = hc.return_value
     nginx_manager = nginx.Nginx.return_value
     nginx_manager.wait_healthcheck.side_effect = Exception("Nginx timeout")
     manager.new_instance("x")
     self.LoadBalancer.create.assert_called_once()
     lb.add_host.assert_called_once()
     dumb_hc.add_url.assert_not_called()
     lb.destroy.assert_called_once()
     host.destroy.assert_called_once()
     lb.remove_host.assert_not_called()
     dumb_hc.destroy.assert_called_once()
     self.assertEqual(self.storage.find_task("x").count(), 0)
コード例 #11
0
 def test_new_instance_with_extra_tags(self, nginx):
     config = copy.deepcopy(self.config)
     config["INSTANCE_EXTRA_TAGS"] = "enable_monitoring:1"
     manager = Manager(config)
     manager.consul_manager = mock.Mock()
     manager.consul_manager.generate_token.return_value = "abc-123"
     manager.new_instance("x")
     host = self.Host.create.return_value
     config["HOST_TAGS"] = (
         "rpaas_service:test-suite-rpaas,rpaas_instance:x,"
         "consul_token:abc-123,enable_monitoring:1")
     del config["INSTANCE_EXTRA_TAGS"]
     lb = self.LoadBalancer.create.return_value
     self.Host.create.assert_called_with("my-host-manager", "x", config)
     self.LoadBalancer.create.assert_called_with("my-lb-manager", "x",
                                                 config)
     lb.add_host.assert_called_with(host)
     self.assertEquals(manager.storage.find_task("x").count(), 0)
     nginx.Nginx.assert_called_once_with(config)
     nginx_manager = nginx.Nginx.return_value
     nginx_manager.wait_healthcheck.assert_called_once_with(host.dns_name,
                                                            timeout=600)
コード例 #12
0
ファイル: test_manager.py プロジェクト: ricobl/rpaas
 def test_new_instance_over_quota(self, nginx):
     manager = Manager(self.config)
     for name in ["a", "b", "c", "d", "e"]:
         manager.new_instance(name, "myteam")
     with self.assertRaises(QuotaExceededError) as cm:
         manager.new_instance("f", "myteam")
     self.assertEqual(str(cm.exception), "quota execeeded 5/5 used")
     manager.new_instance("f", "otherteam")
コード例 #13
0
ファイル: test_manager.py プロジェクト: carriercomm/rpaas
 def test_new_instance_over_quota(self, nginx):
     manager = Manager(self.config)
     for name in ['a', 'b', 'c', 'd', 'e']:
         manager.new_instance(name, 'myteam')
     with self.assertRaises(QuotaExceededError) as cm:
         manager.new_instance('f', 'myteam')
     self.assertEqual(str(cm.exception), "quota execeeded 5/5 used")
     manager.new_instance('f', 'otherteam')
コード例 #14
0
 def test_new_instance_over_quota(self, nginx):
     manager = Manager(self.config)
     for name in ["a", "b", "c", "d", "e"]:
         manager.new_instance(name, "myteam")
     with self.assertRaises(QuotaExceededError) as cm:
         manager.new_instance("f", "myteam")
     self.assertEqual(str(cm.exception), "quota execeeded 5/5 used")
     manager.new_instance("f", "otherteam")
コード例 #15
0
 def test_new_instance_error_already_running(self):
     self.storage.store_task("x")
     manager = Manager(self.config)
     with self.assertRaises(storage.DuplicateError):
         manager.new_instance("x")
コード例 #16
0
ファイル: test_manager.py プロジェクト: ricobl/rpaas
 def test_new_instance_error_already_exists(self, LoadBalancer):
     LoadBalancer.find.return_value = "something"
     manager = Manager(self.config)
     with self.assertRaises(storage.DuplicateError):
         manager.new_instance("x")
     LoadBalancer.find.assert_called_once_with("x")
コード例 #17
0
ファイル: test_manager.py プロジェクト: ricobl/rpaas
 def test_new_instance_error_already_running(self):
     self.storage.store_task("x")
     manager = Manager(self.config)
     with self.assertRaises(storage.DuplicateError):
         manager.new_instance("x")
コード例 #18
0
ファイル: test_manager.py プロジェクト: ricobl/rpaas
 def test_new_instance_plan_not_found(self):
     manager = Manager(self.config)
     with self.assertRaises(storage.PlanNotFoundError):
         manager.new_instance("x", plan_name="supersmall")
コード例 #19
0
 def test_new_instance_error_already_exists(self, LoadBalancer):
     LoadBalancer.find.return_value = "something"
     manager = Manager(self.config)
     with self.assertRaises(storage.DuplicateError):
         manager.new_instance("x")
     LoadBalancer.find.assert_called_once_with("x")
コード例 #20
0
 def test_new_instance_plan_not_found(self):
     manager = Manager(self.config)
     with self.assertRaises(storage.PlanNotFoundError):
         manager.new_instance("x", plan_name="supersmall")