CiscoUcs/imcsdk

View on GitHub
imcsdk/apis/v2/storage/sdcard.py

Summary

Maintainability
F
1 wk
Test Coverage

File sdcard.py has 667 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2018 Cisco Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in imcsdk/apis/v2/storage/sdcard.py - About 1 day to fix

    Function _sd_card_config_set_m4 has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
    Open

    def _sd_card_config_set_m4(handle, expected_vds, existing_vds, mos_dict=None):
        if mos_dict is None:
            mos_dict = _prepare_mos_dict(handle, expected_vds.keys())
    
        is_mode_changed = False
    Severity: Minor
    Found in imcsdk/apis/v2/storage/sdcard.py - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _sd_card_config_set_m5 has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

    def _sd_card_config_set_m5(handle, expected_vds, existing_vds, mos_dict):
    
        if 'OS' in expected_vds:
            expected_vd = expected_vds['OS']
            existing_vd = existing_vds.get('OS', None)
    Severity: Minor
    Found in imcsdk/apis/v2/storage/sdcard.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _apply_config_card_action_util has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def _apply_config_card_action_util(handle, mos_dict, vds):
        from imcsdk.mometa.storage.StorageFlexFlashVirtualDrive import \
            StorageFlexFlashVirtualDriveConsts
        # slot = _choose_slot(mos_dict['flexflash_pds'])
    
    
    Severity: Minor
    Found in imcsdk/apis/v2/storage/sdcard.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function flexflash_controller_set has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def flexflash_controller_set(handle, admin_action=None, auto_sync=None,
    Severity: Major
    Found in imcsdk/apis/v2/storage/sdcard.py - About 1 hr to fix

      Function _get_existing_vds_m4 has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def _get_existing_vds_m4(mos_dict):
          existing_vds = {}
          flexflash_vds = mos_dict.get("flexflash_vds", None)
          # flexflash_pds = mos_dict.get("flexflash_pds", None)
          if not flexflash_vds:
      Severity: Minor
      Found in imcsdk/apis/v2/storage/sdcard.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _get_existing_vds_m5 has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def _get_existing_vds_m5(mos_dict):
          log.debug("Fetch existing vds of M5 server")
          existing_vds = {}
      
          log.debug("Fetching vds of flexflash controller")
      Severity: Minor
      Found in imcsdk/apis/v2/storage/sdcard.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _compare has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      def _compare(expected_vds, existing_vds):
          exists = True
      
          # change in count of virtual drives
          if len(expected_vds) != len(existing_vds):
      Severity: Minor
      Found in imcsdk/apis/v2/storage/sdcard.py - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _get_expected_vds has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def _get_expected_vds(virtual_drives={}):
          vd_types = [vd for vd in dir(VirtualDriveType)
                      if not vd.startswith('_')]
          expected_vds = {}
      
      
      Severity: Minor
      Found in imcsdk/apis/v2/storage/sdcard.py - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Avoid too many return statements within this function.
      Open

                  return
      Severity: Major
      Found in imcsdk/apis/v2/storage/sdcard.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return False
        Severity: Major
        Found in imcsdk/apis/v2/storage/sdcard.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return True
          Severity: Major
          Found in imcsdk/apis/v2/storage/sdcard.py - About 30 mins to fix

            Similar blocks of code found in 4 locations. Consider refactoring.
            Open

                if response:
                    ret = process_conf_mos_response(response, api, False,
                                                    'Configuring virtual drives failed',
                                                    util_mode_cb,
                                                    dn_to_vd_dict)
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 3 other locations - About 7 hrs to fix
            imcsdk/apis/v2/admin/snmp.py on lines 449..462
            imcsdk/apis/v2/admin/snmp.py on lines 868..881
            imcsdk/apis/v2/server/vmedia.py on lines 255..266

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 114.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if mos_disable:
                    dn_to_vd_dict = {}
                    for mo in mos_disable:
                        vd_type_ = vd_map_id_type_util_m5[int(mo.partition_id)]
                        dn_to_vd_dict[mo.dn] = vd_type_
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 5 hrs to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 663..671

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 88.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if mos_enable:
                    dn_to_vd_dict = {}
                    for mo in mos_enable:
                        vd_type_ = vd_map_id_type_util_m5[int(mo.partition_id)]
                        dn_to_vd_dict[mo.dn] = vd_type_
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 5 hrs to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 653..661

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 88.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                for mo in mos:
                    class_id = mo.get_class_id()
                    if class_id not in mos_dict:
                        mos_dict[class_id] = []
                    mos_dict[class_id].append(mo)
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 2 hrs to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 209..213

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 51.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                for mo in mos:
                    class_id = mo.get_class_id()
                    if class_id not in mos_dict:
                        mos_dict[class_id] = []
                    mos_dict[class_id].append(mo)
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 2 hrs to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 183..187

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 51.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            def flexflash_controller_get(handle):
                controller = handle.query_classid(
                    class_id=NamingId.STORAGE_FLEX_FLASH_CONTROLLER)
                if not controller:
                    raise ImcOperationError("Get Flex Flash Controller",
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 1 hr to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 111..117

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 46.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            def flexutil_controller_get(handle):
                controller = handle.query_classid(
                    class_id=NamingId.STORAGE_FLEX_UTIL_CONTROLLER)
                if not controller:
                    raise ImcOperationError("Get Flex Util Controller",
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 1 hr to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 102..108

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 46.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if 'OS' in vds and hasattr(vds['OS'], 'vd_name'):
                    non_util_partition_name = vds['OS'].vd_name
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 1 hr to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 348..349

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 39.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if 'USER' in vds and hasattr(vds['USER'], 'vd_name'):
                    partition_name = vds['USER'].vd_name
            Severity: Major
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 1 hr to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 350..351

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 39.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if expected_vds_count == 1 and 'OS' in expected_vds:
                    expected_mode = "mirror"
                else:
                    expected_mode = "util"
            Severity: Minor
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 30 mins to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 513..516

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                if existing_vds_count == 1 and 'OS' in existing_vds:
                    existing_mode = "mirror"
                else:
                    existing_mode = "util"
            Severity: Minor
            Found in imcsdk/apis/v2/storage/sdcard.py and 1 other location - About 30 mins to fix
            imcsdk/apis/v2/storage/sdcard.py on lines 508..511

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status