示例#1
0
 def test_is_ready_mismatch(self):
     # The relation is not ready if database settings (such as the
     # database name) have not been mirrored back.
     for k in ["database", "roles", "extensions"]:
         with self.subTest(f"{k} mismatch"):
             # Requested setting should be available in application
             # shared data. This could be leadership data or a peer
             # relation application databag.
             self.assertFalse(
                 client._is_ready(
                     self.log,
                     {k: "value"},
                     {"egress-subnets": "127.23.0.0/24"},
                     {"allowed-subnets": "127.23.1.0/24"},
                 ))
             self.assertFalse(
                 client._is_ready(
                     self.log,
                     {k: "value"},
                     {"egress-subnets": "127.23.0.0/24"},
                     {
                         "allowed-subnets": "127.23.1.0/24",
                         k: "different"
                     },
                 ))
示例#2
0
 def test_is_ready_no_allowed(self):
     # The relation is not ready if allowed-subnets does not contain our egress-subnets.
     # The remote end has not yet granted the local unit access.
     self.assertFalse(
         client._is_ready(self.log, {}, {"egress-subnets": "127.23.0.0/24"},
                          {}))
     self.assertFalse(
         client._is_ready(self.log, {}, {"egress-subnets": "127.23.0.0/24"},
                          {"allowed-subnets": "127.0.1/24"}))
示例#3
0
 def test_is_ready_no_egress(self):
     # The relation is considered ready if the client has published
     # no egress-subnets. This unexpected result is to support old
     # versions of Juju that predate cross-model relation support.
     # This should not happen with supported Juju versions.
     self.assertTrue(client._is_ready(self.log, {}, {}, {}))
     self.assertTrue(
         client._is_ready(self.log, {}, {},
                          {"allowed-subnets": "127.23.0.0/24"}))
示例#4
0
 def test_is_ready_match(self):
     # The relation is ready if its egress has been allowed access and its
     # settings have been mirrored back, indicating they have been applied.
     app = {}
     loc = {"egress-subnets": "127.0.0.0/24"}
     rel = {"allowed-subnets": "127.0.0.0/24"}
     for k in ["database", "roles", "extensions"]:
         with self.subTest(f"{k} match"):
             # Requested setting should be available in application
             # shared data. This could be leadership data or a peer
             # relation application databag.
             app[k] = "value"
             self.assertFalse(client._is_ready(self.log, app, loc, rel))
             rel[k] = "value"
             self.assertTrue(client._is_ready(self.log, app, loc, rel))
示例#5
0
 def test_is_ready_default_dbname(self):
     # If no database name has been requested, the relation is ready
     # no matter what the published database name is. Ideally
     # the PostgreSQL charm mirrors back the client setting
     # identically (like "roles" and "extensions"), but some legacy
     # clients still use the "database" field to construct their own
     # connection strings rather than using the connection strings
     # provided on the relation.
     app = {}
     loc = {"egress-subnets": "127.0.0.0/24"}
     rel = {"allowed-subnets": "127.0.0.0/24"}
     app["database"] = ""  # Empty string is the default
     app["roles"] = "value"
     self.assertFalse(client._is_ready(self.log, app, loc, rel))
     rel["roles"] = "value"
     rel["database"] = "whatever"
     self.assertTrue(client._is_ready(self.log, app, loc, rel))
示例#6
0
 def test_is_ready_defaults(self):
     # allowed-subnets grants access, and default database settings requested.
     self.assertTrue(
         client._is_ready(
             self.log, {}, {"egress-subnets": "127.23.1.0/24"},
             {"allowed-subnets": "127.23.0.0/24,127.23.1.0/24"}))