

from sahara.conductor import resource as r


def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
    dct = {'name': name, 'tenant_id': tenant, 'plugin_name': plugin,
           'hadoop_version': version, 'node_groups': node_groups}
    dct.update(kwargs)
    return r.ClusterResource(dct)


def make_ng_dict(name, flavor, processes, count, instances=[], **kwargs):
    dct = {'name': name, 'flavor_id': flavor, 'node_processes': processes,
           'count': count, 'instances': instances}
    dct.update(kwargs)
    return dct


def make_inst_dict(inst_id, inst_name):
    return {'instance_id': inst_id, 'instance_name': inst_name}



from sahara.conductor import resource as r


def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
    dct = {'name': name, 'tenant_id': tenant, 'plugin_name': plugin,
           'hadoop_version': version, 'node_groups': node_groups}
    dct.update(kwargs)
    return r.ClusterResource(dct)


def make_ng_dict(name, flavor, processes, count, instances=None, **kwargs):
    instances = instances or []
    dct = {'name': name, 'flavor_id': flavor, 'node_processes': processes,
           'count': count, 'instances': instances}
    dct.update(kwargs)
    return dct


def make_inst_dict(inst_id, inst_name):
    return {'instance_id': inst_id, 'instance_name': inst_name}

Use immutable arg rather mutable arg
Use immutable arg rather mutable arg

Passing mutable objects as default args is a known Python pitfall.
We'd better avoid this. This commit changes mutable default args with
None, then use 'arg = arg or []'.

Change-Id: If3a10d58e6cd792a2011c177c49d3b865a7421ff

  
  
  from sahara.conductor import resource as r
  
  
  def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
      dct = {'name': name, 'tenant_id': tenant, 'plugin_name': plugin,
             'hadoop_version': version, 'node_groups': node_groups}
      dct.update(kwargs)
      return r.ClusterResource(dct)
  
  
- def make_ng_dict(name, flavor, processes, count, instances=[], **kwargs):
+ def make_ng_dict(name, flavor, processes, count, instances=None, **kwargs):
+     instances = instances or []
      dct = {'name': name, 'flavor_id': flavor, 'node_processes': processes,
             'count': count, 'instances': instances}
      dct.update(kwargs)
      return dct
  
  
  def make_inst_dict(inst_id, inst_name):
      return {'instance_id': inst_id, 'instance_name': inst_name}
  
Use immutable arg rather mutable arg
## Code Before:


from sahara.conductor import resource as r


def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
    dct = {'name': name, 'tenant_id': tenant, 'plugin_name': plugin,
           'hadoop_version': version, 'node_groups': node_groups}
    dct.update(kwargs)
    return r.ClusterResource(dct)


def make_ng_dict(name, flavor, processes, count, instances=[], **kwargs):
    dct = {'name': name, 'flavor_id': flavor, 'node_processes': processes,
           'count': count, 'instances': instances}
    dct.update(kwargs)
    return dct


def make_inst_dict(inst_id, inst_name):
    return {'instance_id': inst_id, 'instance_name': inst_name}

## Instruction:
Use immutable arg rather mutable arg
## Code After:


from sahara.conductor import resource as r


def create_cluster(name, tenant, plugin, version, node_groups, **kwargs):
    dct = {'name': name, 'tenant_id': tenant, 'plugin_name': plugin,
           'hadoop_version': version, 'node_groups': node_groups}
    dct.update(kwargs)
    return r.ClusterResource(dct)


def make_ng_dict(name, flavor, processes, count, instances=None, **kwargs):
    instances = instances or []
    dct = {'name': name, 'flavor_id': flavor, 'node_processes': processes,
           'count': count, 'instances': instances}
    dct.update(kwargs)
    return dct


def make_inst_dict(inst_id, inst_name):
    return {'instance_id': inst_id, 'instance_name': inst_name}
