Repository: saltstack/salt
Pull request: add size converter and start convert active size
### What does this PR do?

fix #37093
### What issues does this PR fix or reference?
#37093
### Tests written?

No


Problem statement:
salt remount device every time
### Description of Issue/Question

if we have state with mount

```
/hugetlbfs:
  mount.mounted:
    - device: hugetlbfs
    - fstype: hugetlbfs
    - opts: size=110g,mode=0777
```

and already mount it with options size=110g,mode=0777 salt start remount this device every time.
### Setup

```
/hugetlbfs:
  mount.mounted:
    - device: hugetlbfs
    - fstype: hugetlbfs
    - opts: size=110g,mode=0777

# cat /proc/mounts  | grep huge
hugetlbfs /hugetlbfs hugetlbfs rw,relatime,size=110g,mode=0777 0 0
```
### Steps to Reproduce Issue
### Versions Report

```
Salt Version:
           Salt: 2016.3.1

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.6
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.3.0
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.3 (default, Jun 22 2015, 19:33:41)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.7.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.3
            ZMQ: 3.2.2

System Versions:
           dist: Ubuntu 12.04 precise
        machine: x86_64
        release: 3.18.35-35
         system: Linux
        version: Ubuntu 12.04 precise
```

Hints from issue discussion:

Commit message: add size converter and start convert active size

Patch to review:
diff --git a/salt/states/mount.py b/salt/states/mount.py
index 5761ea9e6d1e..cf4014fbeecc 100644
--- a/salt/states/mount.py
+++ b/salt/states/mount.py
@@ -39,6 +39,15 @@
 log = logging.getLogger(__name__)
 
 
+def _size_convert(_re_size):
+    converted_size = int(_re_size.group('size_value'))
+    if _re_size.group('size_unit') == 'm':
+        converted_size = int(size) * 1024
+    if _re_size.group('size_unit') == 'g':
+        converted_size = int(size) * 1024 * 1024
+    return converted_size
+
+
 def mounted(name,
             device,
             fstype,
@@ -355,11 +364,7 @@ def mounted(name,
 
                     size_match = re.match(r'size=(?P<size_value>[0-9]+)(?P<size_unit>k|m|g)', opt)
                     if size_match:
-                        converted_size = int(size_match.group('size_value'))
-                        if size_match.group('size_unit') == 'm':
-                            converted_size = int(size_match.group('size_value')) * 1024
-                        if size_match.group('size_unit') == 'g':
-                            converted_size = int(size_match.group('size_value')) * 1024 * 1024
+                        converted_size = _size_convert(size_match)
                         opt = "size={0}k".format(converted_size)
                     # make cifs option user synonym for option username which is reported by /proc/mounts
                     if fstype in ['cifs'] and opt.split('=')[0] == 'user':
@@ -378,8 +383,18 @@ def mounted(name,
                                 _id = _info[_param]
                         opt = _param + '=' + str(_id)
 
+                    _active_superopts = active[real_name].get('superopts', [])
+                    for _active_opt in _active_superopts:
+                        size_match = re.match(r'size=(?P<size_value>[0-9]+)(?P<size_unit>k|m|g)', _active_opt)
+                        if size_match:
+                            converted_size = _size_convert(size_match)
+                            opt = "size={0}k".format(converted_size)
+                            _active_superopts.remove(_active_opt)
+                            _active_opt = "size={0}k".format(converted_size)
+                            _active_superopts.append(_active_opt)
+
                     if opt not in active[real_name]['opts'] \
-                    and opt not in active[real_name].get('superopts', []) \
+                    and opt not in _active_superopts \
                     and opt not in mount_invisible_options \
                     and opt not in mount_ignore_fs_keys.get(fstype, []) \
                     and opt not in mount_invisible_keys:


Code review comments:
diff_hunk: @@ -39,6 +39,15 @@
 log = logging.getLogger(__name__)
 
 
+def _size_convert(_re_size):
+    converted_size = int(_re_size.group('size_value'))
+    if _re_size.group('size_unit') == 'm':
+        converted_size = int(size) * 1024
+    if _re_size.group('size_unit') == 'g':
+        converted_size = int(size) * 1024 * 1024
path: salt/states/mount.py
text: @user1:
Same issue here.

diff_hunk: @@ -39,6 +39,15 @@
 log = logging.getLogger(__name__)
 
 
+def _size_convert(_re_size):
+    converted_size = int(_re_size.group('size_value'))
+    if _re_size.group('size_unit') == 'm':
+        converted_size = int(size) * 1024
path: salt/states/mount.py
text: @user1:
It doesn't look like `size` has been defined prior to this.


@author:
Omg! yes. it's my falt. I tested other patch