Exemple #1
0
 def test_retrieve_binds_query(self):
     instance = storage.Instance(name="years")
     bind1 = storage.Bind(app_host="something.where.com", instance=instance)
     self.storage.store_bind(bind1)
     bind2 = storage.Bind(app_host="belong.where.com", instance=instance)
     self.storage.store_bind(bind2)
     self.addCleanup(self.client.feaas_test.binds.remove,
                     {"instance_name": "years"})
     binds = self.storage.retrieve_binds(app_host="belong.where.com")
     binds = [b.to_dict() for b in binds]
     self.assertEqual([bind2.to_dict()], binds)
Exemple #2
0
 def test_update_bind(self):
     instance = storage.Instance(name="great")
     bind = storage.Bind("wat.g1.cloud.tsuru.io", instance)
     self.storage.store_bind(bind)
     self.addCleanup(self.storage.remove_bind, bind)
     self.storage.update_bind(bind, state="created")
     bind = self.storage.retrieve_binds(instance_name="great")[0]
     self.assertEqual("created", bind.state)
Exemple #3
0
 def test_remove_bind(self):
     instance = storage.Instance(name="years")
     bind = storage.Bind(app_host="something.where.com", instance=instance)
     self.storage.store_bind(bind)
     self.addCleanup(self.client.feaas_test.binds.remove,
                     {"instance_name": "years"})
     self.storage.remove_bind(bind)
     self.assertEqual([],
                      self.storage.retrieve_binds(instance_name="years"))
Exemple #4
0
 def test_run_binds(self):
     units = [
         storage.Unit(id="i-0800",
                      dns_name="unit1.cloud.tsuru.io",
                      secret="abc123",
                      state="started"),
         storage.Unit(id="i-8001",
                      dns_name="unit2.cloud.tsuru.io",
                      secret="abc321",
                      state="started")
     ]
     instance1 = storage.Instance(name="wat", units=units)
     instance2 = storage.Instance(name="wet", units=units)
     binds = [
         storage.Bind(instance=instance1, app_host="cool",
                      state="creating"),
         storage.Bind(instance=instance2, app_host="bool", state="creating")
     ]
     strg = mock.Mock()
     strg.retrieve_units.return_value = units
     strg.retrieve_binds.return_value = binds
     manager = mock.Mock(storage=strg)
     writer = vcl_writer.VCLWriter(manager, max_items=3)
     writer.locker = mock.Mock()
     writer.run_binds()
     writer.locker.lock.assert_called_with(vcl_writer.BINDS_LOCKER)
     writer.locker.unlock.assert_called_with(vcl_writer.BINDS_LOCKER)
     strg.retrieve_units.assert_called_once_with(
         state="started", instance_name={"$in": ["wat", "wet"]})
     strg.retrieve_binds.assert_called_once_with(state="creating", limit=3)
     expected_write_vcl_calls = [
         mock.call("unit1.cloud.tsuru.io", "abc123", "cool"),
         mock.call("unit2.cloud.tsuru.io", "abc321", "cool"),
         mock.call("unit1.cloud.tsuru.io", "abc123", "bool"),
         mock.call("unit2.cloud.tsuru.io", "abc321", "bool")
     ]
     self.assertEqual(expected_write_vcl_calls,
                      manager.write_vcl.call_args_list)
     expected_update_bind_calls = [
         mock.call(binds[0], state="created"),
         mock.call(binds[1], state="created")
     ]
     self.assertEqual(expected_update_bind_calls,
                      strg.update_bind.call_args_list)
Exemple #5
0
 def test_to_dict(self):
     instance = storage.Instance(name="myinstance")
     bind = storage.Bind("wat.g1.cloud.tsuru.io", instance)
     expected = {
         "app_host": "wat.g1.cloud.tsuru.io",
         "instance_name": "myinstance",
         "created_at": bind.created_at,
         "state": bind.state
     }
     self.assertEqual(expected, bind.to_dict())
Exemple #6
0
 def test_store_bind(self):
     instance = storage.Instance(name="years")
     bind = storage.Bind(app_host="something.where.com", instance=instance)
     self.storage.store_bind(bind)
     self.addCleanup(self.client.feaas_test.binds.remove,
                     {"instance_name": "years"})
     got = self.client.feaas_test.binds.find_one({"instance_name": "years"})
     expected = bind.to_dict()
     expected["_id"] = got["_id"]
     expected["created_at"] = got["created_at"]
     self.assertEqual(expected, got)
Exemple #7
0
 def test_remove_instance_with_binds(self):
     units = [
         storage.Unit(dns_name="instance1.cloud.tsuru.io", id="i-0800"),
         storage.Unit(dns_name="instance2.cloud.tsuru.io", id="i-0801"),
         storage.Unit(dns_name="instance3.cloud.tsuru.io", id="i-0802")
     ]
     instance = storage.Instance(name="secret", units=units)
     self.storage.store_instance(instance)
     bind = storage.Bind("myapp.cloud.tsuru.io", instance)
     self.storage.store_bind(bind)
     self.storage.remove_instance(instance.name)
     self.assertIsNone(
         self.client.feaas_test.binds.find_one(
             {"instance_name": instance.name}))
Exemple #8
0
 def test_bind_units(self):
     instance1 = storage.Instance(name="myinstance")
     instance2 = storage.Instance(name="yourinstance")
     units = [
         storage.Unit(dns_name="instance1-1.cloud.tsuru.io",
                      id="i-0800",
                      instance=instance1,
                      secret="abc123"),
         storage.Unit(dns_name="instance1-2.cloud.tsuru.io",
                      id="i-0801",
                      instance=instance1,
                      secret="abc321"),
         storage.Unit(dns_name="instance2-1.cloud.tsuru.io",
                      id="i-0802",
                      instance=instance2,
                      secret="abc456")
     ]
     strg = mock.Mock()
     strg.retrieve_units.return_value = units
     strg.retrieve_binds.return_value = [
         storage.Bind("myapp.cloud.tsuru.io", instance1)
     ]
     manager = mock.Mock(storage=strg)
     writer = vcl_writer.VCLWriter(manager, max_items=3)
     writer.bind_units(units)
     expected_calls = [
         mock.call(instance_name="myinstance", state="created"),
         mock.call(instance_name="yourinstance", state="created")
     ]
     self.assertEqual(expected_calls, strg.retrieve_binds.call_args_list)
     expected_calls = [
         mock.call("instance1-1.cloud.tsuru.io", "abc123",
                   "myapp.cloud.tsuru.io"),
         mock.call("instance1-2.cloud.tsuru.io", "abc321",
                   "myapp.cloud.tsuru.io"),
         mock.call("instance2-1.cloud.tsuru.io", "abc456",
                   "myapp.cloud.tsuru.io")
     ]
     self.assertEqual(expected_calls, manager.write_vcl.call_args_list)
Exemple #9
0
 def unbind(self, name, app_host):
     instance = self.storage.retrieve_instance(name=name)
     for unit in instance.units:
         self.remove_vcl(unit.dns_name, unit.secret)
     bind = storage.Bind(app_host, instance)
     self.storage.remove_bind(bind)
Exemple #10
0
 def bind(self, name, app_host):
     instance = self.storage.retrieve_instance(name=name)
     bind = storage.Bind(app_host, instance)
     self.storage.store_bind(bind)