[2.0b5] p.refresh.get_swap_size misconverting units

Bug #1587896 reported by Gavin Panella on 2016-06-01
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MAAS
High
Lee Trager

Bug Description

On my local machine swapon(8) shows 6438252544 bytes of swap:

  $ swapon --bytes --show
  NAME      TYPE            SIZE USED PRIO
  /dev/dm-1 partition 6438252544    0   -1

whereas get_swap_size() returns 6287356000:

  $ bin/py
  >>> from provisioningserver.refresh import get_swap_size
  >>> get_swap_size()
  6287356000

get_swap_size is defined like so:

  def get_swap_size():
      with open('/proc/meminfo') as f:
          for line in f:
              if 'SwapTotal' in line:
                  return int(line.split()[1]) * 1000
      return 0

which seems reasonable because /proc/meminfo uses kB as the unit:

  $ egrep ^SwapTotal /proc/meminfo
  SwapTotal:       6287356 kB

but get_swap_size should be multiplying by 1024, i.e. kiB, to get the
correct byte count. Or, perhaps better, it should sum byte counts as
shown by swapon(8):

  $ swapon --noheadings --raw --bytes --show=SIZE
  6438252544

Related branches

Blake Rouse (blake-rouse) wrote :

It this is being placed in the "swap_size" field on a Machine this is incorrect. This is basically breaking the information of that machine that MAAS deployed.

This is not an issue on a pure rack controller, but it is a problem on a machine that was converted into a rack controller. It is reseting the value that should be unchanged while a machine is deployed. By allowing this field to be changed when it was a machine is incorrect.

I feel like gather this information on a rack controller is not that important anyway. It is not something we gather from a commissioning machine, because it is something you set when you configure a machine for deployment.

Lee Trager (ltrager) wrote :

Its getting the swap size and updating as the user changes in the same way we update the networking information. If the user went through the effort the change the swap size on a deployed system they'd likely want it to stick.

I can create a patch to use swapon if that would be the preferred method.

Changed in maas:
assignee: nobody → Lee Trager (ltrager)

The preferred is not to grab swap size. We don't need it. It is not a piece
of information we gather on commissioning either.

On Thursday, June 2, 2016, Lee Trager <email address hidden> wrote:

> Its getting the swap size and updating as the user changes in the same
> way we update the networking information. If the user went through the
> effort the change the swap size on a deployed system they'd likely want
> it to stick.
>
> I can create a patch to use swapon if that would be the preferred
> method.
>
> ** Changed in: maas
> Assignee: (unassigned) => Lee Trager (ltrager)
>
> --
> You received this bug notification because you are subscribed to MAAS.
> https://bugs.launchpad.net/bugs/1587896
>
> Title:
> [2.0b5] p.refresh.get_swap_size misconverting units
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/maas/+bug/1587896/+subscriptions
>

--
Andres Rodriguez (RoAkSoAx)
Ubuntu Server Developer
MSc. Telecom & Networking
Systems Engineer

Lee Trager (ltrager) on 2016-06-02
Changed in maas:
status: Triaged → In Progress
Changed in maas:
status: In Progress → Fix Committed
Changed in maas:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers