Skip to content

Commit

Permalink
junix util for listing bonding interfaces
Browse files Browse the repository at this point in the history
Bug-Url: #258
Signed-off-by: Laszlo Hornyak <[email protected]>
  • Loading branch information
K0zka committed May 6, 2019
1 parent 5a8f19b commit 40e0471
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ object Bonding : AbstractProcFs {
"active backup" to BondingMode.ActiveBackup
)

fun listBondInterfaces(session: ClientSession) = session.createSftpClient().use { sftp ->
sftp.open("/proc/net/bonding").use { handle -> sftp.listDir(handle).map { it.filename } }
}

fun getBondInfo(session: ClientSession, bondInterface: String): BondingInfo {
val sections = session.getFileContents("/proc/net/bonding/$bondInterface")
.split("\n\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ class BondingTest {
)
}

@Test
fun listBondInterfaces() {
val session = mock<ClientSession>()
val sftpClient = mock<SftpClient>()
whenever(session.createSftpClient()).thenReturn(sftpClient)
val handle = mock<SftpClient.CloseableHandle>()
whenever(sftpClient.open(eq("/proc/net/bonding"))).thenReturn(handle)
val bond0 = mock<SftpClient.DirEntry>()
whenever(bond0.filename).thenReturn("bond0")
val bond1 = mock<SftpClient.DirEntry>()
whenever(bond1.filename).thenReturn("bond1")
whenever(sftpClient.listDir(eq(handle))).thenReturn(listOf(bond0, bond1))

val interfaces = Bonding.listBondInterfaces(session)

assertEquals(listOf("bond0", "bond1"), interfaces)
}

@Test
fun getBondInfo() {
val session = mock<ClientSession>()
Expand Down

0 comments on commit 40e0471

Please sign in to comment.