def test_find_image_differences_new_images(self):
     images_with_new = copy.deepcopy(TEST_IMAGES)
     images_with_new.append(sb.ImageInput("SteamOS", "ffff", "uvwx"))
     self.assertEqual(
         {"new": set(["SteamOS"]), "changed": set(), "retired": set()},
         sb.find_image_differences(TEST_IMAGES, images_with_new),
     )
     images_with_new.append(sb.ImageInput("WindowsServer2012", "gggg", "yzab"))
     self.assertEqual(
         {"new": set(["SteamOS", "WindowsServer2012"]), "changed": set(), "retired": set()},
         sb.find_image_differences(TEST_IMAGES, images_with_new),
     )
 def test_find_image_differences_retired_images(self):
     images_with_retired = copy.deepcopy(TEST_IMAGES)
     images_with_retired.pop(0)
     self.assertEqual(
         {"new": set(), "changed": set(), "retired": set(["Ubuntu"])},
         sb.find_image_differences(TEST_IMAGES, images_with_retired),
     )
     images_with_retired.pop(0)
     self.assertEqual(
         {"new": set(), "changed": set(), "retired": set(["Ubuntu", "CentOS"])},
         sb.find_image_differences(TEST_IMAGES, images_with_retired),
     )
 def test_find_image_differences_retired_images(self):
     images_with_retired = copy.deepcopy(TEST_IMAGES)
     images_with_retired.pop(0)
     self.assertEqual({'new': set(),
                       'changed': set(),
                       'retired': set(['Ubuntu'])},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_retired))
     images_with_retired.pop(0)
     self.assertEqual({'new': set(),
                       'changed': set(),
                       'retired': set(['Ubuntu', 'CentOS'])},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_retired))
 def test_find_image_differences_retired_images(self):
     images_with_retired = copy.deepcopy(TEST_IMAGES)
     images_with_retired.pop(0)
     self.assertEqual({'new': set(),
                       'changed': set(),
                       'retired': set(['Ubuntu'])},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_retired))
     images_with_retired.pop(0)
     self.assertEqual({'new': set(),
                       'changed': set(),
                       'retired': set(['Ubuntu', 'CentOS'])},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_retired))
 def test_find_image_differences_changed_images(self):
     images_with_changed = copy.deepcopy(TEST_IMAGES)
     images_with_changed.pop(0)
     images_with_changed.append(sb.ImageInput("Ubuntu", "aaab", "abce"))
     self.assertEqual(
         {"new": set(), "changed": set(["Ubuntu"]), "retired": set()},
         sb.find_image_differences(TEST_IMAGES, images_with_changed),
     )
     images_with_changed.pop(0)
     images_with_changed.append(sb.ImageInput("CentOS", "bbbc", "efgi"))
     self.assertEqual(
         {"new": set(), "changed": set(["Ubuntu", "CentOS"]), "retired": set()},
         sb.find_image_differences(TEST_IMAGES, images_with_changed),
     )
 def test_find_image_differences_new_images(self):
     images_with_new = copy.deepcopy(TEST_IMAGES)
     images_with_new.append(sb.ImageInput("SteamOS", "ffff", "uvwx"))
     self.assertEqual({'new': set(['SteamOS']),
                       'changed': set(),
                       'retired': set()},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_new))
     images_with_new.append(sb.ImageInput("WindowsServer2012", "gggg",
                                          "yzab"))
     self.assertEqual({'new': set(["SteamOS", "WindowsServer2012"]),
                       'changed': set(),
                       'retired': set()},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_new))
 def test_find_image_differences_changed_images(self):
     images_with_changed = copy.deepcopy(TEST_IMAGES)
     images_with_changed.pop(0)
     images_with_changed.append(sb.ImageInput("Ubuntu", "aaab", "abce"))
     self.assertEqual({'new': set(),
                       'changed': set(['Ubuntu']),
                       'retired': set()},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_changed))
     images_with_changed.pop(0)
     images_with_changed.append(sb.ImageInput("CentOS", "bbbc", "efgi"))
     self.assertEqual({'new': set(),
                       'changed': set(['Ubuntu', 'CentOS']),
                       'retired': set()},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_changed))
 def test_find_image_differences_changed_images(self):
     images_with_changed = copy.deepcopy(TEST_IMAGES)
     images_with_changed.pop(0)
     images_with_changed.append(sb.ImageInput("Ubuntu", "aaab", "abce"))
     self.assertEqual({'new': set(),
                       'changed': set(['Ubuntu']),
                       'retired': set()},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_changed))
     images_with_changed.pop(0)
     images_with_changed.append(sb.ImageInput("CentOS", "bbbc", "efgi"))
     self.assertEqual({'new': set(),
                       'changed': set(['Ubuntu', 'CentOS']),
                       'retired': set()},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_changed))
 def test_find_image_differences_all_diffs(self):
     images_with_all = copy.deepcopy(TEST_IMAGES)
     images_with_all.pop(0)
     images_with_all.pop(0)
     images_with_all.append(sb.ImageInput("Ubuntu", "aaab", "abce"))
     images_with_all.append(sb.ImageInput("SteamOS", "ffff", "uvwx"))
     self.assertEqual(
         {"new": set(["SteamOS"]), "changed": set(["Ubuntu"]), "retired": set(["CentOS"])},
         sb.find_image_differences(TEST_IMAGES, images_with_all),
     )
 def test_find_image_differences_all_diffs(self):
     images_with_all = copy.deepcopy(TEST_IMAGES)
     images_with_all.pop(0)
     images_with_all.pop(0)
     images_with_all.append(sb.ImageInput("Ubuntu", "aaab", "abce"))
     images_with_all.append(sb.ImageInput("SteamOS", "ffff", "uvwx"))
     self.assertEqual({'new': set(['SteamOS']),
                       'changed': set(['Ubuntu']),
                       'retired': set(['CentOS'])},
                      sb.find_image_differences(TEST_IMAGES,
                                                images_with_all))
    def update_current_state(self, nodes, images, flavors):
        # For now, flavors should remain static.
        # In the future we'll handle changing flavor profiles if needed,
        # but it seems unlikely that flavors will change often enough.
        self.flavor_diff = sb.find_flavor_differences(self.current_flavors, flavors)
        sb.log_flavor_differences(self.flavor_diff)
        self.current_flavors = flavors

        # Image differences are important because changed or retired
        # images should be ejected from the cache.
        self.image_diff = sb.find_image_differences(self.current_images, images)
        sb.log_image_differences(self.image_diff)
        self.current_images = images
        self.current_image_uuids = sb.build_attribute_set(images, "uuid")

        # We don't compare old node state versus new, because that would be
        # a relatively large and complicated task. Instead, we only rely on
        # the current state of nodes to inform ourselves whether we're meeting
        # our stated goals or not.
        self.current_nodes = nodes
    def update_current_state(self, nodes, images, flavors):
        # For now, flavors should remain static.
        # In the future we'll handle changing flavor profiles if needed,
        # but it seems unlikely that flavors will change often enough.
        self.flavor_diff = sb.find_flavor_differences(self.current_flavors,
                                                      flavors)
        sb.log_flavor_differences(self.flavor_diff)
        self.current_flavors = flavors

        # Image differences are important because changed or retired
        # images should be ejected from the cache.
        self.image_diff = sb.find_image_differences(self.current_images,
                                                    images)
        sb.log_image_differences(self.image_diff)
        self.current_images = images
        self.current_image_uuids = sb.build_attribute_set(images, 'uuid')

        # We don't compare old node state versus new, because that would be
        # a relatively large and complicated task. Instead, we only rely on
        # the current state of nodes to inform ourselves whether we're meeting
        # our stated goals or not.
        self.current_nodes = nodes
 def test_find_image_differences_no_difference(self):
     empty_diff_dict = {'new': set(), 'changed': set(), 'retired': set()}
     self.assertEqual(empty_diff_dict,
                      sb.find_image_differences([], []))
     self.assertEqual(empty_diff_dict,
                      sb.find_image_differences(TEST_IMAGES, TEST_IMAGES))
 def test_find_image_differences_no_difference(self):
     empty_diff_dict = {'new': set(), 'changed': set(), 'retired': set()}
     self.assertEqual(empty_diff_dict,
                      sb.find_image_differences([], []))
     self.assertEqual(empty_diff_dict,
                      sb.find_image_differences(TEST_IMAGES, TEST_IMAGES))