def test_run_hook_up_dhcp4_prefix(self):
     """Test run_hook filters correctly with older DHCP4_ data."""
     nic = 'eth0'
     dhc.run_hook(nic, 'up', data_d=self.tmp, env=self.ex_env_dhcp4)
     found = dir2dict(self.tmp + os.path.sep)
     self.assertEqual([nic + ".json"], list(found.keys()))
     self.assertEqual(self.expected, json.loads(found[nic + ".json"]))
 def test_run_hook_up_creates_dir(self):
     """If dir does not exist, run_hook should create it."""
     subd = self.tmp_path("subdir", self.tmp)
     nic = 'eth1'
     dhc.run_hook(nic, 'up', data_d=subd, env=self.ex_env)
     self.assertEqual(set([nic + ".json"]),
                      set(dir2dict(subd + os.path.sep)))
 def test_run_hook_up(self):
     """Test expected use of run_hook_up."""
     nic = 'eth0'
     dhc.run_hook(nic, 'up', data_d=self.tmp, env=self.ex_env)
     found = dir2dict(self.tmp + os.path.sep)
     self.assertEqual([nic + ".json"], list(found.keys()))
     self.assertEqual(self.expected, json.loads(found[nic + ".json"]))
 def test_run_hook_down_deletes(self):
     """down should delete the created json file."""
     nic = 'eth1'
     populate_dir(self.tmp, {
         nic + ".json": "{'abcd'}",
         'myfile.txt': 'text'
     })
     dhc.run_hook(nic, 'down', data_d=self.tmp, env={'old_host_name': 'x1'})
     self.assertEqual(set(['myfile.txt']),
                      set(dir2dict(self.tmp + os.path.sep)))
 def test_run_hook_down_deletes(self):
     """down should delete the created json file."""
     nic = "eth1"
     populate_dir(
         self.tmp, {nic + ".json": "{'abcd'}", "myfile.txt": "text"}
     )
     dhc.run_hook(nic, "down", data_d=self.tmp, env={"old_host_name": "x1"})
     self.assertEqual(
         set(["myfile.txt"]), set(dir2dict(self.tmp + os.path.sep))
     )