示例#1
0
    def test_device(self):
        # Create app
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY)

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

        # Create node
        node_req = {}
        node_req['cluster'] = cluster['id']
        node_req['zone'] = 10
        node_req['hostnames'] = {
            "manage": ["node1-manage.gluster.lab.com"],
            "storage": ["node1-storage.gluster.lab.com"]
        }

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

        # Create a device request
        device_req = {}
        device_req['name'] = "sda"
        device_req['weight'] = 100
        device_req['node'] = node['id']

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

        # Get node information
        info = c.node_info(node['id'])
        self.assertEqual(True, len(info['devices']) == 1)
        self.assertEqual(True, len(info['devices'][0]['bricks']) == 0)
        self.assertEqual(True,
                         info['devices'][0]['name'] == device_req['name'])
        self.assertEqual(True,
                         info['devices'][0]['weight'] == device_req['weight'])
        self.assertEqual(True, info['devices'][0]['id'] != '')

        # Get info from an unknown id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_info("badid")

        # Get device information
        device_info = c.device_info(info['devices'][0]['id'])
        self.assertEqual(True, device_info == info['devices'][0])

        # Try to delete node, and will not until we delete the device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete(node['id'])

        # Delete unknown device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete("badid")

        # Delete device
        device_delete = c.device_delete(device_info['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)
示例#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
        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)
示例#3
0
    def test_device(self):
        # Create app
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY)

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

        # Create node
        node_req = {}
        node_req['cluster'] = cluster['id']
        node_req['zone'] = 10
        node_req['hostnames'] = {
            "manage": ["node1-manage.gluster.lab.com"],
            "storage": ["node1-storage.gluster.lab.com"]
        }

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

        # Create a device request
        device_req = {}
        device_req['name'] = "sda"
        device_req['node'] = node['id']

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

        # Get node information
        info = c.node_info(node['id'])
        self.assertEqual(True, len(info['devices']) == 1)
        self.assertEqual(True, len(info['devices'][0]['bricks']) == 0)
        self.assertEqual(
            True, info['devices'][0]['name'] == device_req['name'])
        self.assertEqual(True, info['devices'][0]['id'] != '')

        # Get info from an unknown id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_info("badid")

        # Get device information
        device_id = info['devices'][0]['id']
        device_info = c.device_info(device_id)
        self.assertEqual(True, device_info == info['devices'][0])

        # Set offline
        state = {}
        state['state'] = 'offline'
        self.assertEqual(True, c.device_state(device_id, state))

        # Get device info
        info = c.device_info(device_id)
        self.assertEqual(info['state'], 'offline')

        state['state'] = 'online'
        self.assertEqual(True, c.device_state(device_id, state))

        info = c.device_info(device_id)
        self.assertEqual(info['state'], 'online')

        # Try to delete node, and will not until we delete the device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete(node['id'])

        # Delete unknown device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete("badid")

        # Delete device
        device_delete = c.device_delete(device_info['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)
示例#4
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)
示例#5
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)
示例#6
0
    def test_device_tags(self):
        # Create app
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY,
                         poll_delay=TEST_POLL_DELAY)

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

        # Create node
        node_req = {}
        node_req['cluster'] = cluster['id']
        node_req['zone'] = 10
        node_req['hostnames'] = {
            "manage": ["node1-manage.gluster.lab.com"],
            "storage": ["node1-storage.gluster.lab.com"]
        }

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

        # Create a device (with tags)
        device_req = {}
        device_req['name'] = "/dev/sda"
        device_req['node'] = node['id']
        device_req["tags"] = {
            "foo": "bar",
            "speed": "ultra",
        }

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

        # get information
        info = c.node_info(node['id'])
        self.assertEqual(len(info['devices']), 1)
        device_id = info['devices'][0]['id']

        # check tags on device
        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "foo": "bar",
            "speed": "ultra",
        })

        # add some new tags
        r = c.device_set_tags(device_id, dict(
            change_type=heketi.TAGS_UPDATE,
            tags={"robot": "calculon"}))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "foo": "bar",
            "speed": "ultra",
            "robot": "calculon",
        })

        # reset tags to empty
        r = c.device_set_tags(device_id, dict(
            change_type=heketi.TAGS_SET,
            tags={}))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertFalse(device_info.get('tags'))

        # add some new tags back
        r = c.device_set_tags(device_id, dict(
            change_type=heketi.TAGS_UPDATE,
            tags={"robot": "calculon", "fish": "blinky"}))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "robot": "calculon",
            "fish": "blinky",
        })

        # delete a particular tag
        r = c.device_set_tags(device_id, dict(
            change_type=heketi.TAGS_DELETE,
            tags={"robot": ""}))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "fish": "blinky",
        })

        # invalid change_type raises error
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_set_tags(device_id, dict(
                change_type="hermes",
                tags={"robot": "flexo"}))

        # invalid tag name raises error
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_set_tags(device_id, dict(
                change_type=heketi.TAGS_UPDATE,
                tags={"": "ok"}))

        # check nothing changed
        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "fish": "blinky",
        })

        # delete device
        self.assertTrue(c.device_state(device_id, {'state': 'offline'}))
        self.assertTrue(c.device_state(device_id, {'state': 'failed'}))
        self.assertTrue(c.device_delete(device_id))

        # 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)
示例#7
0
    def test_device(self):
        # Create app
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY,
                         poll_delay=TEST_POLL_DELAY)

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

        # Create node
        node_req = {}
        node_req['cluster'] = cluster['id']
        node_req['zone'] = 10
        node_req['hostnames'] = {
            "manage": ["node1-manage.gluster.lab.com"],
            "storage": ["node1-storage.gluster.lab.com"]
        }

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

        # Create a device request
        device_req = {}
        device_req['name'] = "/dev/sda"
        device_req['node'] = node['id']

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

        # Get node information
        info = c.node_info(node['id'])
        self.assertEqual(len(info['devices']), 1)
        self.assertEqual(len(info['devices'][0]['bricks']), 0)
        self.assertEqual(info['devices'][0]['name'], device_req['name'])
        self.assertNotEqual(info['devices'][0]['id'], '')

        # Get info from an unknown id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_info("badid")

        # Get device information
        device_id = info['devices'][0]['id']
        device_info = c.device_info(device_id)
        self.assertEqual(device_info, info['devices'][0])

        # Set offline
        state = {}
        state['state'] = 'offline'
        self.assertTrue(c.device_state(device_id, state))

        # Get device info
        info = c.device_info(device_id)
        self.assertEqual(info['state'], 'offline')

        state['state'] = 'online'
        self.assertTrue(c.device_state(device_id, state))

        info = c.device_info(device_id)
        self.assertEqual(info['state'], 'online')

        # Resync device
        device_resync = c.device_resync(device_id)
        self.assertTrue(device_resync)

        # Try to delete node, and will not until we delete the device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete(node['id'])

        # Delete unknown device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete("badid")

        # Set device to offline
        state = {}
        state['state'] = 'offline'
        self.assertTrue(c.device_state(device_id, state))

        # Set device to failed
        state = {}
        state['state'] = 'failed'
        self.assertTrue(c.device_state(device_id, state))

        # Delete device
        device_delete = c.device_delete(device_info['id'])
        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)
示例#8
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)
示例#9
0
    def test_device(self):
        # Create app
        c = HeketiClient(TEST_SERVER, "admin", TEST_ADMIN_KEY)

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

        # Create node
        node_req = {}
        node_req['cluster'] = cluster['id']
        node_req['zone'] = 10
        node_req['hostnames'] = {
            "manage": ["node1-manage.gluster.lab.com"],
            "storage": ["node1-storage.gluster.lab.com"]
        }

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

        # Create a device request
        device_req = {}
        device_req['name'] = "/dev/sda"
        device_req['node'] = node['id']

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

        # Get node information
        info = c.node_info(node['id'])
        self.assertEqual(len(info['devices']), 1)
        self.assertEqual(len(info['devices'][0]['bricks']), 0)
        self.assertEqual(info['devices'][0]['name'], device_req['name'])
        self.assertNotEqual(info['devices'][0]['id'], '')

        # Get info from an unknown id
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_info("badid")

        # Get device information
        device_id = info['devices'][0]['id']
        device_info = c.device_info(device_id)
        self.assertEqual(device_info, info['devices'][0])

        # Set offline
        state = {}
        state['state'] = 'offline'
        self.assertTrue(c.device_state(device_id, state))

        # Get device info
        info = c.device_info(device_id)
        self.assertEqual(info['state'], 'offline')

        state['state'] = 'online'
        self.assertTrue(c.device_state(device_id, state))

        info = c.device_info(device_id)
        self.assertEqual(info['state'], 'online')

        # Resync device
        device_resync = c.device_resync(device_id)
        self.assertTrue(device_resync)

        # Try to delete node, and will not until we delete the device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete(node['id'])

        # Delete unknown device
        with self.assertRaises(requests.exceptions.HTTPError):
            c.node_delete("badid")

        # Set device to offline
        state = {}
        state['state'] = 'offline'
        self.assertTrue(c.device_state(device_id, state))

        # Set device to failed
        state = {}
        state['state'] = 'failed'
        self.assertTrue(c.device_state(device_id, state))

        # Delete device
        device_delete = c.device_delete(device_info['id'])
        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)
示例#10
0
    def test_device_tags(self):
        # Create app
        c = HeketiClient(TEST_SERVER,
                         "admin",
                         TEST_ADMIN_KEY,
                         poll_delay=TEST_POLL_DELAY)

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

        # Create node
        node_req = {}
        node_req['cluster'] = cluster['id']
        node_req['zone'] = 10
        node_req['hostnames'] = {
            "manage": ["node1-manage.gluster.lab.com"],
            "storage": ["node1-storage.gluster.lab.com"]
        }

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

        # Create a device (with tags)
        device_req = {}
        device_req['name'] = "/dev/sda"
        device_req['node'] = node['id']
        device_req["tags"] = {
            "foo": "bar",
            "speed": "ultra",
        }

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

        # get information
        info = c.node_info(node['id'])
        self.assertEqual(len(info['devices']), 1)
        device_id = info['devices'][0]['id']

        # check tags on device
        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "foo": "bar",
            "speed": "ultra",
        })

        # add some new tags
        r = c.device_set_tags(
            device_id,
            dict(change_type=heketi.TAGS_UPDATE, tags={"robot": "calculon"}))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "foo": "bar",
            "speed": "ultra",
            "robot": "calculon",
        })

        # reset tags to empty
        r = c.device_set_tags(device_id,
                              dict(change_type=heketi.TAGS_SET, tags={}))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertFalse(device_info.get('tags'))

        # add some new tags back
        r = c.device_set_tags(
            device_id,
            dict(change_type=heketi.TAGS_UPDATE,
                 tags={
                     "robot": "calculon",
                     "fish": "blinky"
                 }))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "robot": "calculon",
            "fish": "blinky",
        })

        # delete a particular tag
        r = c.device_set_tags(
            device_id, dict(change_type=heketi.TAGS_DELETE, tags={"robot":
                                                                  ""}))
        self.assertTrue(r)

        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "fish": "blinky",
        })

        # invalid change_type raises error
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_set_tags(
                device_id, dict(change_type="hermes", tags={"robot": "flexo"}))

        # invalid tag name raises error
        with self.assertRaises(requests.exceptions.HTTPError):
            c.device_set_tags(
                device_id, dict(change_type=heketi.TAGS_UPDATE,
                                tags={"": "ok"}))

        # check nothing changed
        device_info = c.device_info(device_id)
        self.assertEqual(device_info['tags'], {
            "fish": "blinky",
        })

        # delete device
        self.assertTrue(c.device_state(device_id, {'state': 'offline'}))
        self.assertTrue(c.device_state(device_id, {'state': 'failed'}))
        self.assertTrue(c.device_delete(device_id))

        # 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)
    b = client.cluster_info(i)
    f = b.get('nodes')
    g = f[1]

cni = client.node_info(g)
node_info = json.dumps(cni, indent=4, sort_keys=True)
xw.write(node_info)

xw.close()

json_file = open ("nodes.out")
json_data = json.load(json_file)
global name,state,deviceId
for device in json_data['devices']:
    name = device['name']
    state = device['state']
    deviceId = device['id']
    if name == '/dev/sde':
        di = client.device_info(deviceId)
        devinfo = json.dumps(di, indent=4, sort_keys=True)
        node_output.write(devinfo)
        node_output.write('\n')
        client.device_delete(deviceId)
        node_output.write("The device Name {} with Id {} is deleted successfully \n".format(name, deviceId))
        node_output.write('\n')