Ejemplo n.º 1
0
    def test_start_container(self):
        docker = docker_api.from_env()

        # test that once an instance is started that it has an id, ip and key
        sawtooth_instance = SawtoothContainer()
        self.assertEqual(1, len(docker.containers.list()))
        self.assertIsNot(sawtooth_instance.id(), None)
        self.assertIsNot(sawtooth_instance.ip(), None)
        self.assertIsNot(sawtooth_instance.val_key(), None)

        container_ip = docker.containers.list()[0].exec_run("hostname -i").output.decode('utf-8').strip()
        container_val_key = docker.containers.list()[0].exec_run("cat {val_pub}".format(val_pub=VALIDATOR_KEY["pub"])) \
            .output.decode('utf-8').strip()
        container_user_key = docker.containers.list()[0].exec_run("cat {user_pub}".format(user_pub=USER_KEY["pub"])) \
            .output.decode('utf-8').strip()
        container_network = DEFAULT_DOCKER_NETWORK

        self.assertEqual(sawtooth_instance.id(), docker.containers.list()[0].id)
        self.assertEqual(sawtooth_instance.ip(), container_ip)
        self.assertEqual(sawtooth_instance.val_key(), container_val_key)
        self.assertEqual(sawtooth_instance.user_key(), container_user_key)
        self.assertNotEqual(sawtooth_instance.user_key(), sawtooth_instance.val_key())
        self.assertEqual(sawtooth_instance.attached_network(), container_network)

        number_of_running_processes = len(docker.containers.list()[0].top()['Processes'][0])
        # should only be 2 processes bash and tail -f /dev/null
        # each process has 4 columns so 2*4 = 8
        self.assertEqual(8, number_of_running_processes)

        # test that containers are made unique
        sawtooth_instance_2nd = SawtoothContainer()

        self.assertEqual(2, len(docker.containers.list()))
        # tests that the two instance to not have the same IP or Key
        self.assertNotEqual(sawtooth_instance.id(), sawtooth_instance_2nd.id())
        self.assertNotEqual(sawtooth_instance.ip(), sawtooth_instance_2nd.ip())
        self.assertNotEqual(sawtooth_instance.val_key(), sawtooth_instance_2nd.val_key())
        self.assertNotEqual(sawtooth_instance.user_key(), sawtooth_instance_2nd.user_key())

        # clean up
        docker.close()
Ejemplo n.º 2
0
    def test_peer_setup(self):
        a = SawtoothContainer()
        b = SawtoothContainer()
        id_a = '1'
        id_b = '2'
        inter = Intersection(a, b, id_a, id_b)

        self.assertEqual(inter.committee_id_a, id_a)
        self.assertEqual(inter.committee_id_b, id_b)
        self.assertEqual(inter.ip(id_a), a.ip())
        self.assertEqual(inter.ip(id_b), b.ip())
        self.assertEqual(inter.attached_network(), DEFAULT_DOCKER_NETWORK)
        self.assertTrue(inter.in_committee(id_a))
        self.assertTrue(inter.in_committee(id_b))
        self.assertFalse(inter.in_committee('c'))
        self.assertFalse(inter.in_committee(0))

        del a, b, inter
        a = SawtoothContainer('host')
        b = SawtoothContainer('host')
        id_a = '1'
        id_b = '2'
        inter = Intersection(a, b, id_a, id_b)
        self.assertEqual(inter.attached_network(), 'host')