Ejemplo n.º 1
0
    def test_volume(self):
        # Create cluster
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY)
        self.assertEqual(True, c != '')

        cluster = c.cluster_create()
        self.assertEqual(True, cluster['id'] != '')

        # Create node request packet
        for i in range(4):
            node_req = {}
            node_req['cluster'] = cluster['id']
            node_req['hostnames'] = {
                "manage": ["node%s-manage.gluster.lab.com" % (i)],
                "storage": ["node%s-storage.gluster.lab.com" % (i)]
            }
            node_req['zone'] = i + 1

            # Create node
            node = c.node_add(node_req)
            self.assertEqual(True, node['id'] != '')

            # Create and add devices
            for i in range(1, 20):
                device_req = {}
                device_req['name'] = "sda%s" % (i)
                device_req['weight'] = 100
                device_req['node'] = node['id']

                device = c.device_add(device_req)
                self.assertEqual(True, device)

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(True, len(list['volumes']) == 0)

        # Create a volume
        volume_req = {}
        volume_req['size'] = 10
        volume = c.volume_create(volume_req)
        self.assertEqual(True, volume['id'] != "")
        self.assertEqual(True, volume['size'] == volume_req['size'])

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(True, len(list['volumes']) == 1)
        self.assertEqual(True, list['volumes'][0] == volume['id'])

        # Get info on incorrect id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_info("badid")

        # Get info
        info = c.volume_info(volume['id'])
        self.assertEqual(True, info == volume)

        # Expand volume with a bad id
        volume_ex_params = {}
        volume_ex_params['expand_size'] = 10

        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_expand("badid", volume_ex_params)

        # Expand volume
        volumeInfo = c.volume_expand(volume['id'], volume_ex_params)
        self.assertEqual(True, volumeInfo['size'] == 20)

        # Delete bad id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_delete("badid")

        # Delete volume
        volume_delete = c.volume_delete(volume['id'])
        self.assertEqual(True, volume_delete)

        clusterInfo = c.cluster_info(cluster['id'])
        for node_id in clusterInfo['nodes']:
            #Get node information
            nodeInfo = c.node_info(node_id)

            # Delete all devices
            for device in nodeInfo['devices']:
                device_delete = c.device_delete(device['id'])
                self.assertEqual(True, device_delete)

            #Delete node
            node_delete = c.node_delete(node_id)
            self.assertEqual(True, node_delete)

        # Delete cluster
        cluster_delete = c.cluster_delete(cluster['id'])
        self.assertEqual(True, cluster_delete)
Ejemplo n.º 2
0
    def test_volume(self):
        # Create cluster
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY)
        self.assertEqual(True, c != '')

        cluster = c.cluster_create()
        self.assertEqual(True, cluster['id'] != '')

        # Create node request packet
        print "Creating Cluster"
        for i in range(3):
            node_req = {}
            node_req['cluster'] = cluster['id']
            node_req['hostnames'] = {
                "manage": ["node%s-manage.gluster.lab.com" % (i)],
                "storage": ["node%s-storage.gluster.lab.com" % (i)]}
            node_req['zone'] = i + 1

            # Create node
            node = c.node_add(node_req)
            self.assertEqual(True, node['id'] != '')

            # Create and add devices
            for i in range(1, 4):
                device_req = {}
                device_req['name'] = "sda%s" % (i)
                device_req['node'] = node['id']

                device = c.device_add(device_req)
                self.assertEqual(True, device)

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(True, len(list['volumes']) == 0)

        # Create a volume
        print "Creating a volume"
        volume_req = {}
        volume_req['size'] = 10
        volume = c.volume_create(volume_req)
        self.assertEqual(True, volume['id'] != "")
        self.assertEqual(True, volume['size'] == volume_req['size'])

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(True, len(list['volumes']) == 1)
        self.assertEqual(True, list['volumes'][0] == volume['id'])

        # Get info on incorrect id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_info("badid")

        # Get info
        info = c.volume_info(volume['id'])
        self.assertEqual(True, info == volume)

        # Expand volume with a bad id
        volume_ex_params = {}
        volume_ex_params['expand_size'] = 10

        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_expand("badid", volume_ex_params)

        # Expand volume
        print "Expanding volume"
        volumeInfo = c.volume_expand(volume['id'], volume_ex_params)
        self.assertEqual(True, volumeInfo['size'] == 20)

        # Delete bad id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_delete("badid")

        # Delete volume
        print "Deleting volume"
        volume_delete = c.volume_delete(volume['id'])
        self.assertEqual(True, volume_delete)

        print "Deleting Cluster"
        clusterInfo = c.cluster_info(cluster['id'])
        for node_id in clusterInfo['nodes']:
            # Get node information
            nodeInfo = c.node_info(node_id)

            # Delete all devices
            for device in nodeInfo['devices']:
                device_delete = c.device_delete(device['id'])
                self.assertEqual(True, device_delete)

            # Delete node
            node_delete = c.node_delete(node_id)
            self.assertEqual(True, node_delete)

        # Delete cluster
        cluster_delete = c.cluster_delete(cluster['id'])
        self.assertEqual(True, cluster_delete)
Ejemplo n.º 3
0
    def test_volume(self):
        # Create cluster
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY)
        self.assertEqual(True, c != '')

        cluster_req = {}
        cluster_req['block'] = True
        cluster_req['file'] = True
        cluster = c.cluster_create(cluster_req)
        self.assertNotEqual(cluster['id'], '')

        # Create node request packet
        print("Creating Cluster")
        for i in range(3):
            node_req = {}
            node_req['cluster'] = cluster['id']
            node_req['hostnames'] = {
                "manage": ["node%s-manage.gluster.lab.com" % (i)],
                "storage": ["node%s-storage.gluster.lab.com" % (i)]
            }
            node_req['zone'] = i + 1

            # Create node
            node = c.node_add(node_req)
            self.assertNotEqual(node['id'], '')

            # Create and add devices
            for i in range(1, 4):
                device_req = {}
                device_req['name'] = "/dev/sda%s" % (i)
                device_req['node'] = node['id']

                device = c.device_add(device_req)
                self.assertTrue(device)

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(len(list['volumes']), 0)

        # Create a volume
        print("Creating a volume")
        volume_req = {}
        volume_req['size'] = 10
        volume = c.volume_create(volume_req)
        self.assertNotEqual(volume['id'], "")
        self.assertEqual(volume['size'], volume_req['size'])

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(len(list['volumes']), 1)
        self.assertEqual(list['volumes'][0], volume['id'])

        # Get info on incorrect id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_info("badid")

        # Get info
        info = c.volume_info(volume['id'])
        self.assertEqual(info, volume)

        # Expand volume with a bad id
        volume_ex_params = {}
        volume_ex_params['expand_size'] = 10

        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_expand("badid", volume_ex_params)

        # Expand volume
        print("Expanding volume")
        volumeInfo = c.volume_expand(volume['id'], volume_ex_params)
        self.assertEqual(volumeInfo['size'], 20)

        # Delete bad id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_delete("badid")

        # Delete volume
        print("Deleting volume")
        volume_delete = c.volume_delete(volume['id'])
        self.assertTrue(volume_delete)

        print("Deleting Cluster")
        clusterInfo = c.cluster_info(cluster['id'])
        for node_id in clusterInfo['nodes']:
            # Get node information
            nodeInfo = c.node_info(node_id)

            # Delete all devices
            for device in nodeInfo['devices']:
                devid = device['id']
                self.assertTrue(c.device_state(devid, {'state': 'offline'}))
                self.assertTrue(c.device_state(devid, {'state': 'failed'}))
                device_delete = c.device_delete(devid)
                self.assertTrue(device_delete)

            # Delete node
            node_delete = c.node_delete(node_id)
            self.assertTrue(node_delete)

        # Delete cluster
        cluster_delete = c.cluster_delete(cluster['id'])
        self.assertTrue(cluster_delete)
Ejemplo n.º 4
0
    def test_volume(self):
        # Create cluster
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY,
                         poll_delay=TEST_POLL_DELAY)
        self.assertEqual(True, c != '')

        cluster_req = {}
        cluster_req['block'] = True
        cluster_req['file'] = True
        cluster = c.cluster_create(cluster_req)
        self.assertNotEqual(cluster['id'], '')

        # Create node request packet
        print ("Creating Cluster")
        for i in range(3):
            node_req = {}
            node_req['cluster'] = cluster['id']
            node_req['hostnames'] = {
                "manage": ["node%s-manage.gluster.lab.com" % (i)],
                "storage": ["node%s-storage.gluster.lab.com" % (i)]}
            node_req['zone'] = i + 1

            # Create node
            node = c.node_add(node_req)
            self.assertNotEqual(node['id'], '')

            # Create and add devices
            for i in range(1, 4):
                device_req = {}
                device_req['name'] = "/dev/sda%s" % (i)
                device_req['node'] = node['id']

                device = c.device_add(device_req)
                self.assertTrue(device)

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(len(list['volumes']), 0)

        # Create a volume
        print ("Creating a volume")
        volume_req = {}
        volume_req['size'] = 10
        volume = c.volume_create(volume_req)
        self.assertNotEqual(volume['id'], "")
        self.assertEqual(volume['size'], volume_req['size'])

        # Get list of volumes
        list = c.volume_list()
        self.assertEqual(len(list['volumes']), 1)
        self.assertEqual(list['volumes'][0], volume['id'])

        # Get info on incorrect id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_info("badid")

        # Get info
        info = c.volume_info(volume['id'])
        self.assertEqual(info, volume)

        # Expand volume with a bad id
        volume_ex_params = {}
        volume_ex_params['expand_size'] = 10

        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_expand("badid", volume_ex_params)

        # Expand volume
        print ("Expanding volume")
        volumeInfo = c.volume_expand(volume['id'], volume_ex_params)
        self.assertEqual(volumeInfo['size'], 20)

        # Delete bad id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.volume_delete("badid")

        # Delete volume
        print ("Deleting volume")
        volume_delete = c.volume_delete(volume['id'])
        self.assertTrue(volume_delete)

        print ("Deleting Cluster")
        clusterInfo = c.cluster_info(cluster['id'])
        for node_id in clusterInfo['nodes']:
            # Get node information
            nodeInfo = c.node_info(node_id)

            # Delete all devices
            for device in nodeInfo['devices']:
                devid = device['id']
                self.assertTrue(c.device_state(devid, {'state': 'offline'}))
                self.assertTrue(c.device_state(devid, {'state': 'failed'}))
                device_delete = c.device_delete(devid)
                self.assertTrue(device_delete)

            # Delete node
            node_delete = c.node_delete(node_id)
            self.assertTrue(node_delete)

        # Delete cluster
        cluster_delete = c.cluster_delete(cluster['id'])
        self.assertTrue(cluster_delete)
for i in a:
    client.cluster_info(i)
    xw.write('Heketi Cluster information for Id {} Begins \n'.format(i))
    b = client.cluster_info(i)
    cluster_info = json.dumps(b, indent=4, sort_keys=True)
    xw.write(cluster_info + "\n\n")
    f = b.get('nodes')
    g = b.get('volumes')

    xw.write('\n\n\n\n')
    xw.write('Node Information for the Cluster Begins \n\n')

    for i in f:
        client.node_info(i)
        xw.write('Node Info for Id {} is \n'.format(i))
        cni = client.node_info(i)
        node_info = json.dumps(cni, indent=4, sort_keys=True)
        xw.write(node_info + "\n\n")

    xw.write('\n\n\n\n')
    xw.write('Volume Information for the Cluster Begins \n\n')

    for i in g:
        client.volume_info(i)
        xw.write('Volume Info for Id {} is \n'.format(i))
        cvi = client.volume_info(i)
        volume_info = json.dumps(cvi, indent=4, sort_keys=True)
        xw.write(volume_info + "\n\n")

xw.close()