Beispiel #1
0
 def test_get_all_keys(self):
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("network.dhcp.startip", "192.168.1.1")
     client.set("network.dhcp.endip", "192.168.1.100")
     client.set("network.dhcp.interfaces", ["eth0", "eth1"])
     client.set("my.service.restarter", True)
     client.set("network.breakfast", "waffles")
     client.set("network.lease", 1440)
     client.commit()
     resp = set(map(lambda x: x.key, client.get("network.dhcp.*").get.kvs))
     self.assertEqual(
         set([
             "network.dhcp.startip", "network.dhcp.endip",
             "network.dhcp.interfaces"
         ]), resp)
     resp = map(lambda x: UnpackFromProto(x.value),
                client.get("network.dhcp.*").get.kvs)
     self.assertEqual(3, len(resp))
     self.assertTrue("192.168.1.1" in resp)
     self.assertTrue("192.168.1.100" in resp)
     self.assertTrue(["eth0", "eth1"] in resp)
     resp = set(map(lambda x: x.key, client.get("network.*").get.kvs))
     self.assertEqual(
         set([
             "network.dhcp.startip", "network.dhcp.endip",
             "network.dhcp.interfaces", "network.breakfast", "network.lease"
         ]), resp)
     resp = map(lambda x: UnpackFromProto(x.value),
                client.get("network.*").get.kvs)
     self.assertEqual(5, len(resp))
     self.assertTrue("192.168.1.1" in resp)
     self.assertTrue("192.168.1.100" in resp)
     self.assertTrue(["eth0", "eth1"] in resp)
     self.assertTrue("waffles" in resp)
     self.assertTrue(1440 in resp)
Beispiel #2
0
 def test_new_key_migration(self):
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("network.dhcp.startip", "192.168.1.1")
     client.set("network.dhcp.endip", "192.168.1.100")
     client.set("network.dhcp.interfaces", ["eth0", "eth1"])
     client.set("my.service.restarter", True)
     client.set("network.breakfast", "waffles")
     client.set("network.lease", 1440)
     client.commit()
     m = SysAdminMigrator(client)
     m.new_keys({"new.key": "value"})
     client.commit()
     self.assertEqual(
         "value", UnpackFromProto(client.get("new.key").get.kvs[0].value))
     m.change_values({"new.key": "4"})
     client.commit()
     self.assertEqual(
         "4", UnpackFromProto(client.get("new.key").get.kvs[0].value))
     m.change_types({"new.key": "int32"})
     client.commit()
     self.assertEqual(
         4, UnpackFromProto(client.get("new.key").get.kvs[0].value))
     m.rename_keys([{"new.key": "renamed.key"}])
     client.commit()
     self.assertEqual(
         4, UnpackFromProto(client.get("renamed.key").get.kvs[0].value))
     m.remove_keys(["new.key"])
     client.commit()
     self.assertEqual(
         4, UnpackFromProto(client.get("renamed.key").get.kvs[0].value))
Beispiel #3
0
 def test_basic_drop(self):
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("wireless.wl0.psk", "password")
     client.set("wireless.wl0.channel", 40)
     client.drop()
     self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND,
                      client.get("wireless.wl0.psk").status)
     self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND,
                      client.get("wireless.wl0.channel").status)
Beispiel #4
0
 def test_new_key_rollback(self):
     #make a commit with a new key and value, ensure that a rollback can remove the key
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("cheese", 42)
     self.assertEqual(1, client.commit().commit.commit_id)
     self.assertEqual(
         42, UnpackFromProto(client.get("cheese").get.kvs[0].value))
     self.assertEqual(sysadminctl_pb2.SUCCESS, client.rollback(1).status)
     self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND,
                      client.get("cheese").status)
Beispiel #5
0
 def test_change_types(self):
     client = SysAdminClient("127.0.0.1", 4000)
     m = SysAdminMigrator(client)
     m.new_keys({"gonna.be.list": "value"})
     client.commit()
     m.change_types({"gonna.be.list": "stringlist"})
     client.commit()
     self.assertEqual(["value"],
                      UnpackFromProto(
                          client.get("gonna.be.list").get.kvs[0].value))
     m.change_types({"gonna.be.list": "str"})
     client.commit()
     self.assertEqual(
         "value",
         UnpackFromProto(client.get("gonna.be.list").get.kvs[0].value))
     m.new_keys({"gonna.be.intlist": "4"})
     client.commit()
     m.change_types({"gonna.be.intlist": "int32list"})
     client.commit()
     self.assertEqual([4],
                      UnpackFromProto(
                          client.get("gonna.be.intlist").get.kvs[0].value))
     m.change_types({"gonna.be.intlist": "str"})
     client.commit()
     self.assertEqual(
         "4",
         UnpackFromProto(client.get("gonna.be.intlist").get.kvs[0].value))
     m.new_keys({"gonna.be.boollist": "true"})
     client.commit()
     m.change_types({"gonna.be.boollist": "boollist"})
     client.commit()
     self.assertEqual([True],
                      UnpackFromProto(
                          client.get("gonna.be.boollist").get.kvs[0].value))
     m.change_types({"gonna.be.boollist": "str"})
     client.commit()
     self.assertEqual(
         "True",
         UnpackFromProto(client.get("gonna.be.boollist").get.kvs[0].value))
     m.new_keys({"long.list": ["stringlist", "4", "5", "6"]})
     client.commit()
     m.change_types({"long.list": "int32list"})
     client.commit()
     self.assertEqual([4, 5, 6],
                      UnpackFromProto(
                          client.get("long.list").get.kvs[0].value))
     m.change_types({"long.list": "int32list"})
     client.commit()
     self.assertEqual([4, 5, 6],
                      UnpackFromProto(
                          client.get("long.list").get.kvs[0].value))
     m.change_types({"long.list": "stringlist"})
     client.commit()
     self.assertEqual(["4", "5", "6"],
                      UnpackFromProto(
                          client.get("long.list").get.kvs[0].value))
Beispiel #6
0
    def test_new_key_migration(self):
        client = SysAdminClient("127.0.0.1", 4000)
        client.set("network.dhcp.startip", "192.168.1.1")
        client.set("network.dhcp.endip", "192.168.1.100")
        client.set("network.dhcp.interfaces", ["eth0", "eth1"])
        client.set("my.service.restarter", True)
        client.set("network.breakfast", "eggs")
        client.set("network.lease", 1440)
        client.set("default.network.breakfast", "waffles")
        client.set("default.network.lease", 1440)
        client.commit()

        client.reset()
        resp = client.get("network.dhcp.startip")
        self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND, resp.status)
        self.assertEqual(
            "waffles",
            UnpackFromProto(client.get("network.breakfast").get.kvs[0].value))
Beispiel #7
0
 def test_erase(self):
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("wireless.wl0.psk", "password")
     client.set("wireless.wl0.channel", 40)
     client.set("wireless.wl0.enabled", True)
     client.set("wireless.wl0.frequencies", [1, 2, 3])
     client.commit()
     self.assertEqual(
         "password",
         UnpackFromProto(client.get("wireless.wl0.psk").get.kvs[0].value))
     client.erase("wireless.wl0.psk")
     self.assertEqual(
         "password",
         UnpackFromProto(client.get("wireless.wl0.psk").get.kvs[0].value))
     client.erase("not.a.key")
     client.commit()
     self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND,
                      client.get("wireless.wl0.psk").status)
Beispiel #8
0
def FetchAllValues(keys):
    client = SysAdminClient("127.0.0.1", 4000)
    output = {}
    for arg in keys:
        resp = client.get(arg)
        if resp.status == sysadminctl_pb2.SUCCESS:
            for value in resp.get.kvs:
                output[value.key] = UnpackFromProto(value.value)
        elif "last." not in arg:
            raise Exception("Could not find required key. Key %s, Error: %s" % (arg, resp.status))
    return condense(output)
Beispiel #9
0
 def test_overridden_xid(self):
     # This client gets the regular sysadmin assigned id
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("network.dhcp.startip", "192.168.1.1")
     client.set("network.dhcp.endip", "192.168.1.100")
     # This client has a overridden id 0
     otherclient = SysAdminClient("127.0.0.1", 4000, 0)
     # This client can't commit the original clients changes
     otherclient.commit()
     self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND,
                      client.get("network.dhcp.startip").status)
     self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND,
                      client.get("network.dhcp.endip").status)
     client.commit()
     self.assertEqual(
         "192.168.1.1",
         UnpackFromProto(
             client.get("network.dhcp.startip").get.kvs[0].value))
     self.assertEqual(
         "192.168.1.100",
         UnpackFromProto(client.get("network.dhcp.endip").get.kvs[0].value))
Beispiel #10
0
 def test_type_checking(self):
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("wireless.wl0.psk", "password")
     resp = client.set("wireless.wl0.psk", 5)
     self.assertEqual(sysadminctl_pb2.SUCCESS, resp.status)
     client.commit()
     resp = client.set("wireless.wl0.psk", "password")
     self.assertEqual(sysadminctl_pb2.TYPE_MISMATCH, resp.status)
     client.commit()
     self.assertEqual(
         5,
         UnpackFromProto(client.get("wireless.wl0.psk").get.kvs[0].value))
Beispiel #11
0
    def test_basic_sets(self):
        # one in-flight
        client = SysAdminClient("127.0.0.1", 4000)
        resp = client.set("wireless.wl0.ssid", "cheese")
        self.assertEqual("wireless.wl0.ssid", resp.get.kvs[0].key)
        self.assertEqual("cheese", UnpackFromProto(resp.get.kvs[0].value))
        resp = client.get("wireless.wl0.ssid")
        self.assertEqual(sysadminctl_pb2.KEY_NOT_FOUND, resp.status)
        client.commit()
        resp = client.get("wireless.wl0.ssid")
        self.assertEqual("cheese", UnpackFromProto(resp.get.kvs[0].value))

        # multiple in-flight, one erasing the other
        client.set("wireless.wl0.psk", "password")
        client.set("wireless.wl0.channel", 40)
        client.set("wireless.wl0.channel", 60)
        client.set("wireless.wl0.enabled", True)
        client.set("wireless.wl0.frequencies", [1, 2, 3])
        client.commit()
        self.assertEqual(
            60,
            UnpackFromProto(
                client.get("wireless.wl0.channel").get.kvs[0].value))
        self.assertEqual(
            "password",
            UnpackFromProto(client.get("wireless.wl0.psk").get.kvs[0].value))
        self.assertEqual(
            True,
            UnpackFromProto(
                client.get("wireless.wl0.enabled").get.kvs[0].value))
        self.assertEqual(
            [1, 2, 3],
            UnpackFromProto(
                client.get("wireless.wl0.frequencies").get.kvs[0].value))
Beispiel #12
0
 def test_basic_rollback(self):
     # This client gets the regular sysadmin assigned id
     client = SysAdminClient("127.0.0.1", 4000)
     client.set("network.dhcp.startip", "192.168.1.1")
     client.set("network.dhcp.endip", "192.168.1.100")
     self.assertEqual(1, client.commit().commit.commit_id)
     client.set("network.dhcp.startip", "10.0.0.1")
     client.set("network.dhcp.endip", "10.0.0.100")
     self.assertEqual(2, client.commit().commit.commit_id)
     # Can't rollback the first commit
     self.assertEqual(sysadminctl_pb2.FAILED_ROLLBACK,
                      client.rollback(1).status)
     self.assertEqual(sysadminctl_pb2.SUCCESS, client.rollback(2).status)
     self.assertEqual(
         "192.168.1.1",
         UnpackFromProto(
             client.get("network.dhcp.startip").get.kvs[0].value))
     self.assertEqual(sysadminctl_pb2.FAILED_ROLLBACK,
                      client.rollback(100).status)