Exemple #1
0
class TestRemoveImage(TestCase):
    """
    Imports an Image and calls the remove image rest call
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)
        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def runTest(self):
        data = {
            constants.PROJECT_PARAMETER: PROJECT,
            constants.IMAGE_NAME_PARAMETER: EXIST_IMG_NAME
        }
        res = requests.delete(PICASSO_URL + "remove_image/",
                              data=data,
                              auth=(CORRECT_HIL_USERNAME,
                                    CORRECT_HIL_PASSWORD))
        self.assertEqual(res.status_code, 200)

    def tearDown(self):
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #2
0
class TestCopyImage(TestCase):
    """
    Creating a flatten copy of an image
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)

        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def runTest(self):
        response = self.good_bmi.copy_image(EXIST_IMG_NAME, PROJECT, IMG2)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)
        images = self.db.image.fetch_images_from_project(PROJECT)
        exists_image = False
        for image in images:
            if IMG2 == image:
                exists_image = True
                break
        self.assertTrue(exists_image)
        with ceph.RBD(_cfg.fs, _cfg.iscsi.password) as fs:
            img_id = self.good_bmi.get_ceph_image_name_from_project(
                IMG2, PROJECT)
            fs.get_image(img_id)

    def tearDown(self):
        self.good_bmi.remove_image(IMG2)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #3
0
 def setUp(self):
     self.db = Database()
     self.db.project.insert(PROJECT)
     self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                         PROJECT)
     self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
     self.good_bmi.create_disk(NEW_DISK, EXIST_IMG_NAME)
Exemple #4
0
 def setUp(self):
     self.db = Database()
     self.db.project.insert(PROJECT, NETWORK)
     self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                         PROJECT)
     self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
     self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK, NIC)
     time.sleep(constants.HIL_CALL_TIMEOUT)
Exemple #5
0
class TestDeprovision(TestCase):
    """
    Same as above, but calls deprovision in the test (Test is same as previous)
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)

        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK, NIC)
        time.sleep(constants.HIL_CALL_TIMEOUT)

    def runTest(self):
        response = self.good_bmi.deprovision(NODE_NAME, NETWORK, NIC)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)
        time.sleep(constants.HIL_CALL_TIMEOUT)

    def tearDown(self):
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
class TestDeprovision(TestCase):
    """
    Same as above, but calls deprovision in the test (Test is same as previous)
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)

        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK, NIC)
        time.sleep(constants.HIL_CALL_TIMEOUT)

    def runTest(self):
        response = self.good_bmi.deprovision(NODE_NAME, NETWORK, NIC)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)
        time.sleep(constants.HIL_CALL_TIMEOUT)

    def tearDown(self):
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #7
0
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)

        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.create_disk(NEW_DISK, EXIST_IMG_NAME)
        time.sleep(constants.HIL_CALL_TIMEOUT)

        self.good_bmi.create_snapshot(NEW_DISK, NEW_SNAP_NAME)
Exemple #8
0
class TestProvision(TestCase):
    """
    Tests Rest Provision call by importing an image and calling provision
    """

    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)
        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def runTest(self):
        data = {constants.PROJECT_PARAMETER: PROJECT,
                constants.NODE_NAME_PARAMETER: NODE_NAME,
                constants.IMAGE_NAME_PARAMETER: EXIST_IMG_NAME,
                constants.NETWORK_PARAMETER: NETWORK,
                constants.NIC_PARAMETER: NIC}
        res = requests.put(PICASSO_URL + "provision/", data=data,
                           auth=(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD))
        self.assertEqual(res.status_code, 200)
        time.sleep(constants.HIL_CALL_TIMEOUT)

    def tearDown(self):
        self.good_bmi.deprovision(NODE_NAME, NETWORK, NIC)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HIL_CALL_TIMEOUT)
Exemple #9
0
class TestDeprovision(TestCase):
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)
        self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK,NIC)
        time.sleep(constants.HAAS_CALL_TIMEOUT)

    def test_run(self):
        data = {constants.PROJECT_PARAMETER: PROJECT,
                constants.NODE_NAME_PARAMETER: NODE_NAME,
                constants.NETWORK_PARAMETER: NETWORK,
                constants.NIC_PARAMETER: NIC}
        res = requests.delete(url + "deprovision/", data=data,
                              auth=(
                              CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD))
        self.assertEqual(res.status_code, 200)
        time.sleep(constants.HAAS_CALL_TIMEOUT)

    def tearDown(self):
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #10
0
def vulnerability_detection(project, mount_path):
    with BMI(_username, _password, project) as bmi:
        ret = bmi.vulnerability_detection(mount_path)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo('Success')
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #11
0
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)

        self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
Exemple #12
0
    def execute_command(self, credentials, command, args):
        """
        Executes the given BMI command

        :param credentials: The credentials that BMI will use to authenticate.
        :param command: The BMI command to execute
        :param args: The Arguments which should be given to BMI Command
        :return: a dict as { HTTP status code, Output or Error Message }
        """
        try:
            with BMI(credentials) as bmi:
                method_to_call = getattr(BMI, command)
                args.insert(0, bmi)
                args = tuple(args)
                output = method_to_call(*args)
                return output
        except BMIException as ex:
            logger.exception('')
            return {
                constants.STATUS_CODE_KEY: ex.status_code,
                constants.MESSAGE_KEY: str(ex)
            }
        except Exception as ex:
            logger.exception('')
            return {
                constants.STATUS_CODE_KEY: 500,
                constants.MESSAGE_KEY: str(ex)
            }
Exemple #13
0
def map_image(project, img):
    with BMI(_username, _password, project) as bmi:
        ret = bmi.map_image(img)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo('Success')
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #14
0
def unmount_mapped_image(project, mount_path):
    with BMI(_username, _password, project) as bmi:
        ret = bmi.unmount_mapped_image(mount_path)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo('Success')
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #15
0
 def setUp(self):
     self.db = Database()
     self.db.project.insert(PROJECT, NETWORK)
     self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                         PROJECT)
     self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
     self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK,NIC)
     time.sleep(constants.HAAS_CALL_TIMEOUT)
Exemple #16
0
class TestRemoveImage(TestCase):
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)
        self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def test_run(self):
        response = self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

    def tearDown(self):
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #17
0
def export_ceph_image(project, img, name):
    """
    """
    with BMI(_username, _password, project) as bmi:
        ret = bmi.export_ceph_image(img, str(name))
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo("Success")
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #18
0
class TestRemoveImage(TestCase):
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)
        self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def test_run(self):
        data = {constants.PROJECT_PARAMETER: PROJECT,
                constants.IMAGE_NAME_PARAMETER: EXIST_IMG_NAME}
        res = requests.delete(url + "remove_image/", data=data, auth=(
            CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD))
        self.assertEqual(res.status_code, 200)

    def tearDown(self):
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #19
0
class TestRemoveImage(TestCase):
    """
    Imports an image and calls remove image
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)
        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def runTest(self):
        response = self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

    def tearDown(self):
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #20
0
class TestListImages(TestCase):
    """
    Imports an import image and calls the list images rest call
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)
        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def runTest(self):
        data = {constants.PROJECT_PARAMETER: PROJECT}
        res = requests.post(PICASSO_URL + "list_images/",
                            data=data,
                            auth=(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD))
        js = res.json()
        self.assertEqual(res.status_code, 200)
        self.assertEqual(js[0], EXIST_IMG_NAME)

    def tearDown(self):
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #21
0
def list_all_images(s, c, p, project, name, ceph):
    """
    List All Image Present in DB

    \b
    WARNING = User Must be An Admin
    """

    def second_filter():
        if project is None:
            f1 = True
        else:
            f1 = image[2] == project

        if ceph is None:
            f2 = True
        else:
            f2 = image[3] == ceph

        if name is None:
            f3 = True
        else:
            f3 = image[1] == name

        f4 = project is None and ceph is None and name is None

        return (f1 and f2 and f3) or f4

    with BMI(_username, _password, constants.BMI_ADMIN_PROJECT) as bmi:
        ret = bmi.list_all_images()
        if ret[constants.STATUS_CODE_KEY] == 200:
            table = PrettyTable(
                field_names=["Id", "Name", "Project", "Ceph", "Public",
                             "Snapshot",
                             "Parent"])
            images = ret[constants.RETURN_VALUE_KEY]
            for image in images:
                flag = False
                if s and image[5]:
                    flag = second_filter()
                elif c and image[6] != '' and not image[5]:
                    flag = second_filter()
                elif p and image[4]:
                    flag = second_filter()
                elif not s and not c and not p:
                    flag = second_filter()

                if flag:
                    table.add_row(image)
            click.echo(table.get_string())
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #22
0
class TestProvisionDeprovision(TestCase):
    """
    This tests multiple things. It creates an image, then provisions
    from it and then deprovisions the node and delete the image.
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)

        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def runTest(self):
        # First create a disk
        response = self.good_bmi.create_disk(NEW_DISK, EXIST_IMG_NAME)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

        # Then provision a node from that disk
        response = self.good_bmi.provision(NODE_NAME, NEW_DISK, NIC)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

        # Then deprovision that node
        response = self.good_bmi.deprovision(NODE_NAME, NIC)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

        # Delete the disk
        response = self.good_bmi.delete_disk(NEW_DISK)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

    def tearDown(self):
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HIL_CALL_TIMEOUT)
Exemple #23
0
def get_node_ip(project, node):
    """
    Get the IP of Provisioned Node on Provisioning Network

    \b
    Arguments:
    PROJECT  = The HIL Project attached to your credentials
    NODE     = The node whose IP is required
    """
    with BMI(_username, _password, project) as bmi:
        ret = bmi.get_node_ip(node)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo(ret[constants.RETURN_VALUE_KEY])
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #24
0
def move_image(src_project, img1, dest_project, img2):
    """
    Move an image from one project to another

    \b
    Arguments:
    SRC_PROJECT  = The HIL Project attached to your credentials
    IMG1         = The Name of the source image
    DEST_PROJECT = The Destination HIL Project (Can be same as source)
    IMG2         = The Name of the destination image (optional)
    """
    with BMI(_username, _password, src_project) as bmi:
        ret = bmi.move_image(img1, dest_project, img2)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo("Success")
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #25
0
def list_provisioned_nodes(project):
    """
    Lists Provisioned Nodes under a Project.

    \b
    Arguments:
    PROJECT = The HIL Project attached to your credentials
    """
    with BMI(_username, _password, project) as bmi:
        table = PrettyTable(field_names=["Node", "Provisioned Image"])
        ret = bmi.list_provisioned_nodes()
        if ret[constants.STATUS_CODE_KEY] == 200:
            for clone in ret[constants.RETURN_VALUE_KEY]:
                table.add_row(clone)
            click.echo(table.get_string())
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #26
0
def delete_project(project):
    """
    Remove Project From DB

    \b
    WARNING = User Must be An Admin

    \b
    Arguments:
    PROJECT = The Name of Project (A HIL Project must exist)
    """
    with BMI(_username, _password, constants.BMI_ADMIN_PROJECT) as bmi:
        ret = bmi.delete_project(project)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo("Success")
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #27
0
def list_projects():
    """
    Lists Projects From DB

    \b
    WARNING = User Must be An Admin
    """
    with BMI(_username, _password, constants.BMI_ADMIN_PROJECT) as bmi:
        ret = bmi.list_projects()
        if ret[constants.STATUS_CODE_KEY] == 200:
            table = PrettyTable(field_names=["Id", "Name"])
            projects = ret[constants.RETURN_VALUE_KEY]
            for project in projects:
                table.add_row(project)
            click.echo(table.get_string())
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #28
0
def list_disks(project):
    """
    Show all disks that belong to <project>.

    \b
    Arguments:
    PROJECT = The HIL Project attached to your credentials
    """
    with BMI(_username, _password, project) as bmi:
        table = PrettyTable(field_names=["Disk", "Source Image"])
        ret = bmi.list_disks()
        if ret[constants.STATUS_CODE_KEY] == 200:
            for clone in ret[constants.RETURN_VALUE_KEY]:
                table.add_row(clone)
            click.echo(table.get_string())
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #29
0
def add_project(project, network, id):
    """
    Create Project in DB

    \b
    WARNING = User Must be An Admin

    \b
    Arguments:
    PROJECT = The Name of Project (A HIL Project must exist)
    NETWORK = The Name of the Provisioning Network
    """
    with BMI(_username, _password, constants.BMI_ADMIN_PROJECT) as bmi:
        ret = bmi.add_project(project, network, id)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo("Success")
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #30
0
def add_image(project, img, id, snap, parent, public):
    """
    Create Image in DB

    \b
    WARNING = User Must be An Admin

    \b
    Arguments:
    PROJECT = The Name of Project (A HIL Project must exist)
    IMG = The Name of the Image to insert
    """
    with BMI(_username, _password, constants.BMI_ADMIN_PROJECT) as bmi:
        ret = bmi.add_image(project, img, id, snap, parent, public)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo("Success")
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #31
0
def delete_image(project, img):
    """
    Delete Image in DB

    \b
    WARNING = User Must be An Admin

    \b
    Arguments:
    PROJECT = The Name of Project
    IMG     = The Name of the Image to insert
    """
    with BMI(_username, _password, constants.BMI_ADMIN_PROJECT) as bmi:
        ret = bmi.delete_image(project, img)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo("Success")
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #32
0
def delete_mapping(project, img):
    """
    Unmount image from iscsi server

    \b
    WARNING = User Must be An Admin

    \b
    Arguments:
    PROJECT  = The HIL Project attached to your credentials
    IMG      = The image that must be unmounted
    """
    with BMI(_username, _password, project) as bmi:
        ret = bmi.umount_image(img)
        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo('Success')
        else:
            click.echo(ret[constants.MESSAGE_KEY])
Exemple #33
0
def import_ceph_image(project, img, snap, protect):
    """
    Import an existing CEPH image into BMI

    \b
    Arguments:
    PROJECT = The HIL Project attached to your credentials
    IMG = The Name of the CEPH Image to import
    """
    with BMI(_username, _password, project) as bmi:
        ret = None
        if snap is None:
            ret = bmi.import_ceph_image(img)
        else:
            ret = bmi.import_ceph_snapshot(img, snap, protect)

        if ret[constants.STATUS_CODE_KEY] == 200:
            click.echo("Success")
        else:
            click.echo(ret[constants.MESSAGE_KEY])
class TestListImages(TestCase):
    """
    Imports an image and calls list image
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)

        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)

    def runTest(self):
        response = self.good_bmi.list_images()
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)
        self.assertEqual(response[constants.RETURN_VALUE_KEY],
                         [EXIST_IMG_NAME])

    def tearDown(self):
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
Exemple #35
0
class TestCreateSnapshot(TestCase):
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)

        self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK, NIC)
        time.sleep(constants.HAAS_CALL_TIMEOUT)

    def test_run(self):
        response = self.good_bmi.create_snapshot(NODE_NAME, NEW_SNAP_NAME)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

        snaps = self.db.image.fetch_snapshots_from_project(PROJECT)
        has_image = False
        for snapshot in snaps:
            if NEW_SNAP_NAME == snapshot[0]:
                has_image = True
        self.assertTrue(has_image)

        with ceph.RBD(_cfg.fs[constants.CEPH_CONFIG_SECTION_NAME],
                      _cfg.iscsi_update_password) as fs:
            img_id = self.good_bmi.get_ceph_image_name_from_project(
                NEW_SNAP_NAME, PROJECT)
            fs.get_image(img_id)

    def tearDown(self):
        self.good_bmi.deprovision(NODE_NAME, NETWORK, NIC)
        self.good_bmi.remove_image(NEW_SNAP_NAME)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HAAS_CALL_TIMEOUT)
Exemple #36
0
class TestListSnapshots(TestCase):
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)
        self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK,NIC)
        time.sleep(constants.HAAS_CALL_TIMEOUT)

        self.good_bmi.create_snapshot(NODE_NAME, NEW_SNAP_NAME)

    def test_run(self):
        data = {constants.PROJECT_PARAMETER: PROJECT}
        res = requests.post(url + "list_snapshots/", data=data,
                            auth=(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD))
        self.assertEqual(res.status_code, 200)
        js = res.json()
        self.assertEqual(res.status_code, 200)
        self.assertEqual(js[0][0], NEW_SNAP_NAME)

    def tearDown(self):
        self.good_bmi.deprovision(NODE_NAME, NETWORK, NIC)
        self.good_bmi.remove_image(NEW_SNAP_NAME)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HAAS_CALL_TIMEOUT)
Exemple #37
0
class TestListSnapshots(TestCase):
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT, NETWORK)

        self.good_bmi = BMI(CORRECT_HAAS_USERNAME, CORRECT_HAAS_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.provision(NODE_NAME, EXIST_IMG_NAME, NETWORK, NIC)
        time.sleep(constants.HAAS_CALL_TIMEOUT)

        self.good_bmi.create_snapshot(NODE_NAME, NEW_SNAP_NAME)

    def test_run(self):
        response = self.good_bmi.list_snapshots()
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)
        self.assertEqual(response[constants.RETURN_VALUE_KEY][0][0],
                         NEW_SNAP_NAME)

    def tearDown(self):
        self.good_bmi.deprovision(NODE_NAME, NETWORK, NIC)
        self.good_bmi.remove_image(NEW_SNAP_NAME)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HAAS_CALL_TIMEOUT)
Exemple #38
0
class TestListSnapshots(TestCase):
    """
    Does the same steps as previous test and calls list snapshots rest call
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)
        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.create_disk(NEW_DISK, EXIST_IMG_NAME)

        self.good_bmi.create_snapshot(NEW_DISK, NEW_SNAP_NAME)

    def runTest(self):
        data = {constants.PROJECT_PARAMETER: PROJECT}
        res = requests.post(PICASSO_URL + "list_snapshots/",
                            data=data,
                            auth=(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD))
        self.assertEqual(res.status_code, 200)
        js = res.json()
        self.assertEqual(res.status_code, 200)
        self.assertEqual(js[0][0], NEW_SNAP_NAME)

    def tearDown(self):
        self.good_bmi.delete_disk(NEW_DISK)
        self.good_bmi.remove_image(NEW_SNAP_NAME)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HIL_CALL_TIMEOUT)
Exemple #39
0
class TestCreateSnapshot(TestCase):
    """
    Calls provision like TestProvision then creates a snapshot using rest call
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)
        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.create_disk(NEW_DISK, EXIST_IMG_NAME)
        time.sleep(constants.HIL_CALL_TIMEOUT)

    def runTest(self):
        data = {
            constants.PROJECT_PARAMETER: PROJECT,
            constants.DISK_NAME_PARAMETER: NEW_DISK,
            constants.SNAP_NAME_PARAMETER: NEW_SNAP_NAME
        }
        res = requests.put(PICASSO_URL + "create_snapshot/",
                           data=data,
                           auth=(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD))
        self.assertEqual(res.status_code, 200)

        snaps = self.db.image.fetch_snapshots_from_project(PROJECT)
        has_image = False
        for snapshot in snaps:
            if NEW_SNAP_NAME == snapshot[0]:
                has_image = True
        self.assertTrue(has_image)

        with ceph.RBD(_cfg.fs, _cfg.iscsi.password) as fs:
            img_id = self.good_bmi.get_ceph_image_name_from_project(
                NEW_SNAP_NAME, PROJECT)
            fs.get_image(img_id)

    def tearDown(self):
        self.good_bmi.delete_disk(NEW_DISK)
        self.good_bmi.remove_image(NEW_SNAP_NAME)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HIL_CALL_TIMEOUT)
Exemple #40
0
class TestCreateSnapshot(TestCase):
    """
    Provisions an imported image and creates snapshot
    """
    @trace
    def setUp(self):
        self.db = Database()
        self.db.project.insert(PROJECT)

        self.good_bmi = BMI(CORRECT_HIL_USERNAME, CORRECT_HIL_PASSWORD,
                            PROJECT)
        self.good_bmi.import_ceph_image(EXIST_IMG_NAME)
        self.good_bmi.create_disk(NEW_DISK, EXIST_IMG_NAME)
        time.sleep(constants.HIL_CALL_TIMEOUT)

    def runTest(self):
        response = self.good_bmi.create_snapshot(NEW_DISK, NEW_SNAP_NAME)
        self.assertEqual(response[constants.STATUS_CODE_KEY], 200)

        snaps = self.db.image.fetch_snapshots_from_project(PROJECT)
        has_image = False
        for snapshot in snaps:
            if NEW_SNAP_NAME == snapshot[0]:
                has_image = True
        self.assertTrue(has_image)

        with ceph.RBD(_cfg.fs, _cfg.iscsi.password) as fs:
            img_id = self.good_bmi.get_ceph_image_name_from_project(
                NEW_SNAP_NAME, PROJECT)
            fs.get_image(img_id)

    def tearDown(self):
        self.good_bmi.delete_disk(NEW_DISK)
        self.good_bmi.remove_image(NEW_SNAP_NAME)
        self.good_bmi.remove_image(EXIST_IMG_NAME)
        self.db.project.delete_with_name(PROJECT)
        self.db.close()
        self.good_bmi.shutdown()
        time.sleep(constants.HIL_CALL_TIMEOUT)