def setUp(self): logging.getLogger().setLevel(logging.WARN) consul = mock.MagicMock() my = mock.MagicMock() cp = ContainerPilot() cp.load(get_environ()) temp_file = tempfile.NamedTemporaryFile() cp.path = temp_file.name my.datadir = tempfile.mkdtemp() self.node = manage.Node(consul=consul, cp=cp, mysql=my) self.node.ip = '192.168.1.101' self.node.name = 'node1'
def test_update(self): self.environ['CONSUL_AGENT'] = '1' cp = ContainerPilot() cp.state = REPLICA cp.load(envs=self.environ) temp_file = tempfile.NamedTemporaryFile() cp.path = temp_file.name # no update expected cp.update() with open(temp_file.name, 'r') as updated: self.assertEqual(updated.read(), '') # force an update cp.state = PRIMARY cp.update() with open(temp_file.name, 'r') as updated: config = json.loads(updated.read()) self.assertEqual(config['consul'], 'localhost:8500') cmd = config['coprocesses'][0]['command'] host_cfg_idx = cmd.index('-retry-join') + 1 self.assertEqual(cmd[host_cfg_idx], 'my.consul.example.com')
def test_update(self): self.environ['CONSUL_AGENT'] = '1' cp = ContainerPilot() cp.state = REPLICA cp.load(envs=self.environ) temp_file = tempfile.NamedTemporaryFile() cp.path = temp_file.name # no update expected cp.update() with open(temp_file.name, 'r') as updated: self.assertEqual(updated.read(), '') # force an update cp.state = PRIMARY cp.update() with open(temp_file.name, 'r') as updated: config = json.loads(updated.read()) self.assertEqual(config['consul'], 'localhost:8500') cmd = config['coprocesses'][0]['command'] host_cfg_idx = cmd.index('-retry-join') + 1 self.assertEqual(cmd[host_cfg_idx], 'my.consul.example.com:8500')