예제 #1
0
 def test_serialize_policy(self):
     p = Policy.loads(policy_yaml)
     self.assertEqual(p[0].tag, ALPHA)
     self.assertEqual(p[0].block, "diego/geom2(branch1)")
     self.assertEqual(p[1].tag, BETA)
     self.assertEqual(p[1].block, "diego/geom")
     d = p.serialize()
     p2 = Policy.deserialize(d)
     self.assertEqual(p, p2)
예제 #2
0
    def test_evaluate(self):
        p = Policy.loads(policy_yaml)
        m = BlockVersion(BRLBlock('diego/diego/geom/master'), 3)
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(False, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('diego/diego/geom2/branch1'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('diego2/diego2/geom3/branch1'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('anyuser/diego2/geom3/anybranch'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('anyuser/diego2/geom4/anybranch'), 4)
        self.assertEqual(False, p.evaluate(m, ALPHA))
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(False, p.evaluate(m, BETA))
        self.assertEqual(False, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('pepe/diego2/geom4/anybranch'), 4)
        self.assertEqual(False, p.evaluate(m, ALPHA))
        self.assertEqual(False, p.evaluate(m, DEV))
        self.assertEqual(False, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
        m = BlockVersion(BRLBlock('pepe/john/geom4/anybranch'), 4)
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))

        p = Policy.loads("*: DEV")
        m = BlockVersion(BRLBlock('diego/diego/geom/master'), 3)
        self.assertEqual(True, p.evaluate(m, DEV))
        self.assertEqual(True, p.evaluate(m, ALPHA))
        self.assertEqual(True, p.evaluate(m, BETA))
        self.assertEqual(True, p.evaluate(m, STABLE))
    def test_tag_policy_update(self):
        for i, tag in enumerate([BETA, ALPHA, DEV]):
            # Do not update
            request = self.build_update_request(BlockVersion(self.brl, i), self.name)
            result = self.service.find(request, BiiResponse())
            self.check_result(result)

            # update
            request.policy = Policy.loads("*: %s" % tag)
            result = self.service.find(request, BiiResponse())
            self.check_result(result, updated=[(self.brl, i + 1, {self.name})])
    def test_tag_policy_find(self):
        """ change tag policy to find BETA and DEV """
        request = self.build_unresolved_request(self.name)
        request.policy = Policy.loads("*: BETA")
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 1, {self.name})])

        request = self.build_unresolved_request(self.name)
        request.policy = Policy.loads("*: ALPHA")
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 2, {self.name})])

        request = self.build_unresolved_request(self.name)
        request.policy = Policy.loads("*: DEV")
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 3, {self.name})])

        request = self.build_unresolved_request(self.name)
        result = self.service.find(request, BiiResponse())
        self.check_result(result, resolved=[(self.brl, 0, {self.name})])
예제 #5
0
 def test_errors(self):
     with self.assertRaisesRegexp(BiiException, "Incorrect rule in policies.bii"):
         Policy.loads("*: ALFA")
     with self.assertRaisesRegexp(BiiException, "Incorrect rule in policies.bii"):
         Policy.loads("what")
     with self.assertRaisesRegexp(BiiException, "Empty policies.bii, cannot find"):
         Policy.loads("#adasd\n#asdasd\n")
예제 #6
0
 def policies(self):
     if self._policies is None:
         policies_path = self._bii_paths.policies
         if not os.path.exists(policies_path):
             policies = self._user_cache.default_policies
             save(policies_path, policies)
         else:
             policies = load(policies_path)
             # Migration to new simple policies.bii format
             if policies.lstrip().startswith("# This is the file"):
                 self._biiout.warn("Upgrading your find policies to new format")
                 policies = self._user_cache.default_policies
                 save(policies_path, policies)
         if "YOUR_USER_NAME" in policies:
             user = self._user_cache.username
             if user is not None:
                 policies = policies.replace("YOUR_USER_NAME", user)
                 save(policies_path, policies)
         self._policies = Policy.loads(policies)
     return self._policies
예제 #7
0
 def policies(self):
     if self._policies is None:
         policies_path = self._bii_paths.policies
         if not os.path.exists(policies_path):
             policies = self._user_cache.default_policies
             save(policies_path, policies)
         else:
             policies = load(policies_path)
             # Migration to new simple policies.bii format
             if policies.lstrip().startswith("# This is the file"):
                 self._biiout.warn(
                     "Upgrading your find policies to new format")
                 policies = self._user_cache.default_policies
                 save(policies_path, policies)
         if "YOUR_USER_NAME" in policies:
             user = self._user_cache.username
             if user is not None:
                 policies = policies.replace("YOUR_USER_NAME", user)
                 save(policies_path, policies)
         self._policies = Policy.loads(policies)
     return self._policies