示例#1
0
    def test_check_add_only_one_image_with_length_not_4(self):
        x = Images()

        expectedvalue = ['3cfeaf3f0103b9637bb3fcfe691fce1e']

        try:
            x.add(expectedvalue)
        except ValueError as error:
            self.assertEqual(error.message, "Error, data should be a array with len equal to 4")
示例#2
0
    def test_check_add_only_one_image(self):
        x = Images()

        expectedvalue = ['3cfeaf3f0103b9637bb3fcfe691fce1e', 'base_ubuntu_14.04', 'ok', None]
        x.add(expectedvalue)

        self.assertEqual(len(x.images), 1, "Error, number of elements is not equal to 1")
        self.assertEqual(x.images[0].id, '3cfeaf3f0103b9637bb3fcfe691fce1e')
        self.assertEqual(x.images[0].name, 'base_ubuntu_14.04')
        self.assertEqual(x.images[0].status, 'ok')
        self.assertEqual(x.images[0].message, None)
示例#3
0
    def test_check_add_only_one_image_with_length_not_4(self):
        x = Images()

        expectedvalue = ['3cfeaf3f0103b9637bb3fcfe691fce1e']

        try:
            x.add(expectedvalue)
        except ValueError as error:
            self.assertEqual(
                error.message,
                "Error, data should be a array with len equal to 4")
示例#4
0
    def test_check_add_only_one_image(self):
        x = Images()

        expectedvalue = [
            '3cfeaf3f0103b9637bb3fcfe691fce1e', 'base_ubuntu_14.04', 'ok', None
        ]
        x.add(expectedvalue)

        self.assertEqual(len(x.images), 1,
                         "Error, number of elements is not equal to 1")
        self.assertEqual(x.images[0].id, '3cfeaf3f0103b9637bb3fcfe691fce1e')
        self.assertEqual(x.images[0].name, 'base_ubuntu_14.04')
        self.assertEqual(x.images[0].status, 'ok')
        self.assertEqual(x.images[0].message, None)
示例#5
0
    def test_check_dump_more_than_one(self):
        x = Images()

        expectedvalue = [
            '3cfeaf3f0103b9637bb3fcfe691fce1e', 'base_ubuntu_14.04', 'ok', None
        ]
        x.add(expectedvalue)

        expectedvalue = [
            '4rds4f3f0103b9637bb3fcfe691fce1e', 'base_centOS_7',
            'pending_upload', 'fake message'
        ]
        x.add(expectedvalue)

        expectedid = [
            '3cfeaf3f0103b9637bb3fcfe691fce1e',
            '4rds4f3f0103b9637bb3fcfe691fce1e'
        ]
        expectedname = ['base_ubuntu_14.04', 'base_centOS_7']
        expectedstatus = ['ok', 'pending_upload']
        expectedmessage = [None, 'fake message']

        result = x.dump()
        data = json.loads(result)['images']

        for i in range(0, 2):
            self.assertEqual(data[i]['id'], expectedid[i],
                             "The returned JSON is not the expected one")
            self.assertEqual(data[i]['name'], expectedname[i],
                             "The returned JSON is not the expected one")
            self.assertEqual(data[i]['status'], expectedstatus[i],
                             "The returned JSON is not the expected one")
            self.assertEqual(data[i]['message'], expectedmessage[i],
                             "The returned JSON is not the expected one")
示例#6
0
    def test_check_dump(self):
        x = Images()

        expectedvalue = ['3cfeaf3f0103b9637bb3fcfe691fce1e', 'base_ubuntu_14.04', 'ok', None]
        x.add(expectedvalue)

        expectedid = '3cfeaf3f0103b9637bb3fcfe691fce1e'
        expectedname = 'base_ubuntu_14.04'
        expectedstatus = 'ok'
        expectedmessage = None

        result = x.dump()
        data = json.loads(result)['images'][0]

        self.assertEqual(data['id'], expectedid, "The returned JSON is not the expected one")
        self.assertEqual(data['name'], expectedname, "The returned JSON is not the expected one")
        self.assertEqual(data['status'], expectedstatus, "The returned JSON is not the expected one")
        self.assertEqual(data['message'], expectedmessage, "The returned JSON is not the expected one")
示例#7
0
    def test_check_dump(self):
        x = Images()

        expectedvalue = [
            '3cfeaf3f0103b9637bb3fcfe691fce1e', 'base_ubuntu_14.04', 'ok', None
        ]
        x.add(expectedvalue)

        expectedid = '3cfeaf3f0103b9637bb3fcfe691fce1e'
        expectedname = 'base_ubuntu_14.04'
        expectedstatus = 'ok'
        expectedmessage = None

        result = x.dump()
        data = json.loads(result)['images'][0]

        self.assertEqual(data['id'], expectedid,
                         "The returned JSON is not the expected one")
        self.assertEqual(data['name'], expectedname,
                         "The returned JSON is not the expected one")
        self.assertEqual(data['status'], expectedstatus,
                         "The returned JSON is not the expected one")
        self.assertEqual(data['message'], expectedmessage,
                         "The returned JSON is not the expected one")
示例#8
0
def get_status(regionid, token=None):
    """
    Lists information the status of the synchronization of the images in
    the region <regionid>. Keep in mind that <regionid> is the name of
    the region.

    :param regionid: Region name how you can obtain from the Keystone
                     service. Example: Spain2.
    :param token: The token of the request to be authorized.
    :return: JSON response message with the detailed information about
             the images and the sincronization status.
    """

    message = "GET, get information about the synchronization status in the region: {}".format(regionid)

    logger_api.info(message)

    image_name = request.args.get('image')

    glancesync = GlanceSync(options_dict=None)
    list_images = glancesync.get_images_region(regionid, only_tenant_images=False)

    x = Images()
    for item in list_images:
        try:
            if image_name is None or item.name == image_name:
                x.add([item.id, item.name, item.status, None])
        except Exception as e:
            print(e)

    if list_images:
        logger_api.info('Return result: %s', x.dump())
        response = make_response(x.dump(), httplib.OK)
    else:
        response = make_response('{}', httplib.OK)

    response.headers[SERVER_HEADER] = SERVER
    response.headers[CONTENT_TYPE] = JSON_TYPE

    return response
示例#9
0
    def test_check_dump_more_than_one(self):
        x = Images()

        expectedvalue = ['3cfeaf3f0103b9637bb3fcfe691fce1e', 'base_ubuntu_14.04', 'ok', None]
        x.add(expectedvalue)

        expectedvalue = ['4rds4f3f0103b9637bb3fcfe691fce1e', 'base_centOS_7', 'pending_upload', 'fake message']
        x.add(expectedvalue)

        expectedid = ['3cfeaf3f0103b9637bb3fcfe691fce1e', '4rds4f3f0103b9637bb3fcfe691fce1e']
        expectedname = ['base_ubuntu_14.04', 'base_centOS_7']
        expectedstatus = ['ok', 'pending_upload']
        expectedmessage = [None, 'fake message']

        result = x.dump()
        data = json.loads(result)['images']

        for i in range(0, 2):
            self.assertEqual(data[i]['id'], expectedid[i], "The returned JSON is not the expected one")
            self.assertEqual(data[i]['name'], expectedname[i], "The returned JSON is not the expected one")
            self.assertEqual(data[i]['status'], expectedstatus[i], "The returned JSON is not the expected one")
            self.assertEqual(data[i]['message'], expectedmessage[i], "The returned JSON is not the expected one")