Beispiel #1
0
 def test_device_scan_parameter(self):
     """
     Test device_scan across various input.
     """
     # Expected output for a detached or non existent device parameter.
     # This is also the expected output if an empty list is passed.
     out = err = ['']
     rc = 0
     self.assertEqual(device_scan(
         ['detached-ea847422dff841fca3b716fb7dcdaa5a']), (out, err, rc),
                      msg='Failed to ignore detached device.')
     self.mock_os_path_exists.return_value = False
     self.assertEqual(device_scan(['nonexistent-device']), (out, err, rc),
                      msg='Failed to ignore nonexistent-device.')
     self.assertEqual(device_scan([]), (out, err, rc),
                      msg='Failed to ignore empty list.')
     # Test for device_scan having been passed the base device name of a
     # partitioned device.
     # Mockup run_command return values for scanning a partitioned device:
     out = ["Scanning for Btrfs filesystems in '/dev/vdc'", '']
     err = ["ERROR: device scan failed on '/dev/vdc': Invalid argument", '']
     rc = 1
     # To make this test portable we have to mock os.path.exists() as True
     # so that our otherwise bogus block device is considered as existing.
     self.mock_os_path_exists.return_value = True
     self.mock_run_command.return_value = (out, err, rc)
     self.assertEqual(device_scan(['virtio-serial-1']), (out, err, rc),
                      msg='Failed to return results from non btrfs device.')
Beispiel #2
0
def main():

    try:
        device_scan()
    except Exception, e:
        print ('BTRFS device scan failed due to an exception. This indicates '
               'a serious problem. Aborting. Exception: %s' % e.__str__())
        sys.exit(1)
Beispiel #3
0
def main():

    try:
        device_scan()
    except Exception, e:
        print ('BTRFS device scan failed due to an exception. This indicates '
               'a serious problem. Aborting. Exception: %s' % e.__str__())
        sys.exit(1)
Beispiel #4
0
def main():

    try:
        device_scan()
    except Exception as e:
        print(
            "BTRFS device scan failed due to an exception. This indicates "
            "a serious problem. Aborting. Exception: %s" % e.__str__()
        )
        sys.exit(1)
    print("BTRFS device scan complete")

    # if the appliance is not setup, there's nothing more to do beyond
    # device scan
    setup = Setup.objects.first()
    if setup is None or setup.setup_user is False:
        print("Appliance is not yet setup.")
        return

    num_attempts = 0
    while True:
        try:
            aw = APIWrapper()
            time.sleep(2)
            aw.api_call("network")
            aw.api_call("commands/bootstrap", calltype="post")
            break
        except Exception as e:
            # Retry on every exception, primarily because of django-oauth
            # related code behaving unpredictably while setting
            # tokens. Retrying is a decent workaround for now(11302015).
            if num_attempts > 15:
                print(
                    "Max attempts(15) reached. Connection errors persist. "
                    "Failed to bootstrap. Error: %s" % e.__str__()
                )
                sys.exit(1)
            print(
                "Exception occured while bootstrapping. This could be "
                "because rockstor.service is still starting up. will "
                "wait 2 seconds and try again. Exception: %s" % e.__str__()
            )
            time.sleep(2)
            num_attempts += 1
    print("Bootstrapping complete")

    try:
        print("Running qgroup cleanup. %s" % QGROUP_CLEAN)
        run_command([QGROUP_CLEAN])
    except Exception as e:
        print("Exception while running %s: %s" % (QGROUP_CLEAN, e.__str__()))

    try:
        print("Running qgroup limit maxout. %s" % QGROUP_MAXOUT_LIMIT)
        run_command([QGROUP_MAXOUT_LIMIT])
    except Exception as e:
        print("Exception while running %s: %s" % (QGROUP_MAXOUT_LIMIT, e.__str__()))
Beispiel #5
0
def main():

    try:
        device_scan()
    except Exception as e:
        print('BTRFS device scan failed due to an exception. This indicates '
              'a serious problem. Aborting. Exception: %s' % e.__str__())
        sys.exit(1)
    print('BTRFS device scan complete')

    # if the appliance is not setup, there's nothing more to do beyond
    # device scan
    setup = Setup.objects.first()
    if (setup is None or setup.setup_user is False):
        print('Appliance is not yet setup.')
        return

    num_attempts = 0
    while True:
        try:
            aw = APIWrapper()
            time.sleep(2)
            aw.api_call('network')
            aw.api_call('commands/bootstrap', calltype='post')
            break
        except Exception as e:
            # Retry on every exception, primarily because of django-oauth
            # related code behaving unpredictably while setting
            # tokens. Retrying is a decent workaround for now(11302015).
            if (num_attempts > 15):
                print('Max attempts(15) reached. Connection errors persist. '
                      'Failed to bootstrap. Error: %s' % e.__str__())
                sys.exit(1)
            print('Exception occured while bootstrapping. This could be '
                  'because rockstor.service is still starting up. will '
                  'wait 2 seconds and try again. Exception: %s' % e.__str__())
            time.sleep(2)
            num_attempts += 1
    print('Bootstrapping complete')

    try:
        print('Running qgroup cleanup. %s' % QGROUP_CLEAN)
        run_command([QGROUP_CLEAN])
    except Exception as e:
        print('Exception while running %s: %s' % (QGROUP_CLEAN, e.__str__()))

    try:
        print('Running qgroup limit maxout. %s' % QGROUP_MAXOUT_LIMIT)
        run_command([QGROUP_MAXOUT_LIMIT])
    except Exception as e:
        print('Exception while running %s: %s' %
              (QGROUP_MAXOUT_LIMIT, e.__str__()))
    def post(self, request, command):
        if (command == 'bootstrap'):
            try:
                device_scan()
            except Exception, e:
                e_msg = ('Unabled to scan disk drives on the system.')
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)

            for pool in Pool.objects.all():
                disk = Disk.objects.filter(pool=pool)[0].name
                try:
                    mount_root(pool, '/dev/%s' % disk)
                except Exception, e:
                    e_msg = ('Unable to mount a pool(%s) during bootstrap.'
                             % pool.name)
                    logger.exception(e)
Beispiel #7
0
    def post(self, request, command):
        if (command == 'bootstrap'):
            try:
                device_scan()
            except Exception, e:
                e_msg = ('Unabled to scan disk drives on the system.')
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)

            for pool in Pool.objects.all():
                disk = Disk.objects.filter(pool=pool)[0].name
                try:
                    mount_root(pool, '/dev/%s' % disk)
                except Exception, e:
                    e_msg = ('Unable to mount a pool(%s) during bootstrap.' %
                             pool.name)
                    logger.exception(e)
Beispiel #8
0
def main():
    aw = APIWrapper()
    device_scan()
    print('BTRFS device scan complete')

    num_attempts = 0
    while True:
        try:
            aw.api_call('network')
            aw.api_call('commands/bootstrap', calltype='post')
            break
        except requests.exceptions.ConnectionError, e:
            if (num_attempts > 15):
                print('Max attempts(15) reached. Connection errors persist. '
                      'Failed to bootstrap. Error: %s' % e.__str__())
                sys.exit(1)
            print('Connection error while bootstrapping. This could be because '
                  'rockstor.service is still starting up. will wait 2 seconds '
                  'and try again.')
            time.sleep(2)
            num_attempts += 1
Beispiel #9
0
def main():
    baseurl = 'https://localhost/api'
    bootstrap_url = ('%s/commands/bootstrap' % baseurl)
    netscan_url = ('%s/network' % baseurl)
    device_scan()
    print('BTRFS device scan complete')

    num_attempts = 0
    while True:
        try:
            api_call(netscan_url, calltype='get')
            api_call(bootstrap_url, calltype='post')
            break
        except requests.exceptions.ConnectionError, e:
            if (num_attempts > 15):
                print('Max attempts(15) reached. Connection errors persist. '
                      'Failed to bootstrap. Error: %s' % e.__str__())
                sys.exit(1)
            print('Connection error while bootstrapping. This could be because '
                  'rockstor.service is still starting up. will wait 2 seconds '
                  'and try again.')
            time.sleep(2)
            num_attempts += 1
Beispiel #10
0
    def post(self, request, command):
        if (command == 'bootstrap'):
            try:
                device_scan()
            except Exception, e:
                e_msg = ('Unabled to scan disk drives on the system.')
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)

            try:
                device_scan()
                for share in Share.objects.all():
                    if (not is_share_mounted(share.name)):
                        mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                        pool_device = Disk.objects.filter(
                            pool=share.pool)[0].name
                        mount_share(share.subvol_name, pool_device, mnt_pt)
            except Exception, e:
                e_msg = ('Unable to mount a share(%s, %s) during bootstrap.' %
                         (pool_device, mnt_pt))
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)
Beispiel #11
0
def main():
    baseurl = 'https://localhost/api'
    bootstrap_url = ('%s/commands/bootstrap' % baseurl)
    netscan_url = ('%s/network' % baseurl)
    device_scan()
    print('BTRFS device scan complete')

    num_attempts = 0
    while True:
        try:
            api_call(netscan_url, calltype='get')
            api_call(bootstrap_url, calltype='post')
            break
        except requests.exceptions.ConnectionError, e:
            if (num_attempts > 15):
                print('Max attempts(15) reached. Connection errors persist. '
                      'Failed to bootstrap. Error: %s' % e.__str__())
                sys.exit(1)
            print(
                'Connection error while bootstrapping. This could be because '
                'rockstor.service is still starting up. will wait 2 seconds '
                'and try again.')
            time.sleep(2)
            num_attempts += 1
Beispiel #12
0
 def test_device_scan_all(self):
     """
     Test device_scan with no arguments passed which defaults to scanning
     the entire system
     """
     # setup mock output from a successful full system scan ie
     # run_command executing 'btrfs device scan'
     # In system wide scan mode device_scan simply returns the same so
     # these values stand as run_command mock and expected output.
     out = ['Scanning for Btrfs filesystems', '']
     err = ['']
     rc = 0
     self.mock_run_command.return_value = (out, err, rc)
     # Now test device_scan when executing the same, ie via no parameters
     # call where it should return the exact same output.
     self.assertEqual(device_scan(), (out, err, rc),
                      msg="Failed to return results of successful system "
                      "wide 'btrfs device scan'.")