Kushal Das

FOSS and life. Kushal Das talks here.

kushal76uaid62oup5774umh654scnu5dwzh4u2534qxhcbi4wbab3ad.onion

dgplug summer training is coming up

After 10 days, on 18th of June, at 7 PM, the 10th edition of the dgplug summer training will start. There are things need to be done before that. We want to have some more documentation explaining the initial pain points. We will also refresh our how to do IRC document. I am hoping to have some videos as the demo for the sessions.

Guest sessions

This year we are reaching out to much more people for guest sessions. You can find many familiar names in the list of people who already agreed. If you think you help us by sharing your experience with a group of new FOSS contributors (they are also new programmers), this can be a good place. All the sessions are over IRC, so it is fully text based. And, we also have a few bots, and a group of volunteers to help you out during the session. The sessions are generally an hour long, but go on more for much longer time, or you can split it into a few different sessions over time. Here is an example AMA session Guido did last year. If you have any particular topic in mind, feel free share your experience with all of us.

The guest sessions will happen over July/August/September. Drop me a note in case you want to join in.

PyCon Pune 2017

2017 is a special year for various reasons. PyCon Pune 2017 is one of the biggest points in that list. This gave us an opportunity to meet with the friends and work along with the community on the language/projects we love.

Anwesha first pointed out the idea that we can have a regional PyCon, and later in the Delhi airport (while returning from PyCon India) I shared the idea with Sayan and Ratnadeep. The goal was to focus on upstream contribution and communities at the same time. We made the first call for organizers and volunteers as soon as I managed to get a venue fixed. Though just before the conference we had to move the main conference venue (for various reasons) to another beautiful location, AMANORA THE FERN HOTELS AND CLUB, Pune. We had two different part of the conference, first two days were the main conference, a single track of talks. This helped everyone to attend the whole of conference talks. People could also visit the sponsor booths or enjoy the view of the venue in the hallway track. The second part of the conference was dev sprints, which was the main attraction for us. It was held in the Red Hat Pune office in the last 2 days of the conference. Having the sprints in an office helped us to get a stable Internet, and power. In total, we had around 550+ attendees and around 120 dev sprint attendees. The tickets for dev sprints were sold out in the first few days :) and there was a big demand for any ticket transfer till the last moment. We also had child care facility around 5 minutes walking distance from the main venue. Our tshirt had a comment from Brett Cannon, this was also a perfect way to communicate the goal of the conference.

We had 89 talk proposals, out of that 10 talks were selected and 6 keynotes. I should especially thank all the speakers as they traveled of their own, and thus helping with our limited budget for the conference. Btw, I have written another blog post about how do we take care of our conference speakers.

Everything related to the conference was maintained in the github. Our logo came from Ryan Lerch, website was made by a group of volunteers. The local hackerspace, reserved-bit was not only a sponsor for us, but also volunteered to manage the finance of the conference and volunteering in person. They also have a blog post explaining the budget information in their blog. Janastu helped us to manage the ticket (registration) sales. Hasgeek helped by providing the video recording equipment. All the talks (except one where we lost the audio due to a technical issue) are available on youtube.

The Python Software Foundation helped us for this conference from the day 1, PyLadies Pune were managing the PSF booth during the conference. Microsoft Python team, Elastic, Pipal Academy, Red Hat, reserved-bit, PSF were the sponsors in the first edition of the conference.

Devsprints details

As I mentioned above, the dev sprints were the main fun point for PyCon Pune. At the end of two days of sprints, we manage to have the following things done (mostly by total newcomers):

Cpython

  • CuriousLearner (Sanyam Khurana) https://github.com/python/cpython/pull/147
  • aktech (Amit Kumar) https://github.com/python/cpython/pull/146
  • chandankumar https://github.com/python/cpython/pull/148
  • CuriousLearner (Sanyam Khurana) https://github.com/python/cpython/pull/151
  • aktech (Amit Kumar) https://github.com/python/cpython/pull/152
  • CuriousLearner (Sanyam Khurana) https://github.com/python/cpython/pull/156
  • CuriousLearner (Sanyam Khurana) https://github.com/python/cpython/pull/158
  • Sayan Chowdhury https://github.com/python/cpython/pull/175/
  • CuriousLearner (Sanyam Khurana) https://github.com/python/cpython/pull/172
  • rtnpro (Ratnadeep Debnath) https://github.com/python/cpython/pull/173
  • Sayan Chowdhury https://github.com/python/cpython/pull/312
  • Subhendu Ghosh https://github.com/python/cpython/pull/171
  • Subhendu Ghosh https://github.com/python/cpython/pull/150

OpenCabs

  • Rahul Bajaj Fixed doc, https://github.com/rtnpro/opencabs/pull/1
  • Mahendra Yadav Fixed typo, https://github.com/rtnpro/opencabs/pull/2
  • Rahul Bajaj, Fix the index booking form, https://github.com/rtnpro/opencabs/pull/7

Web.py

  • https://github.com/webpy/webpy/commit/f85221ddc7d4a7a31effb0289a760c6e55c59ee9
  • https://github.com/webpy/webpy/commit/fe500832e9517d7a621e1f3703d20884ab8253a8
  • https://github.com/webpy/webpy/commit/2d0b1f1808fb81b808242ee1ea6c409934f97fef
  • https://github.com/webpy/webpy/commit/21dccd0ed8690d2e179183f3e5b98a20e0f8f764
  • https://github.com/webpy/webpy/commit/937904356ebe9e9cba2ab07bdc39194ca319d730

ElasticSearch

  • https://github.com/elastic/elasticsearch-dsl-py/commit/7277c190fb7315fc83b746f228e27b4e6f58ebf0
  • https://github.com/elastic/elasticsearch-dsl-py/commit/f09ff5e747f6320d59fde7b097427e1536962440
  • https://github.com/elastic/elasticsearch-dsl-py/commit/7d06d3ce649df699daa8fe573037a0b731901a22
  • https://github.com/elastic/elasticsearch-dsl-py/commit/6dabbb9e6c3b35f01a996c239e0628cf281b5d46
  • https://github.com/elastic/elasticsearch-py/pull/539

Django

  • https://github.com/django/django/pull/8081

es-django-example

  • https://github.com/HonzaKral/es-django-example/pull/14
  • https://github.com/HonzaKral/es-django-example/pull/13

Pagure

  • https://pagure.io/pagure/pull-request/1945
  • https://pagure.io/pagure/pull-request/1944
  • https://pagure.io/pagure/pull-request/1943
  • https://pagure.io/pagure/pull-request/1942
  • https://pagure.io/pagure/pull-request/1941
  • https://pagure.io/pagure/pull-request/1940
  • https://pagure.io/pagure/pull-request/1939
  • https://pagure.io/pagure/pull-request/1937
  • https://pagure.io/pagure/pull-request/1934
  • https://pagure.io/pagure/pull-request/1947
  • https://pagure.io/pagure/pull-request/1948
  • https://pagure.io/pagure/pull-request/1946
  • https://pagure.io/pagure/pull-request/1936

Learning of all things

  • Getting started with PyGame
  • Getting started with Cactus (static website generating)
  • Using git and github
  • Using github pages

MicroPython

We also had a full room with people working on MicroPython and hardware. John Hawley was helping out people with MicroPython, and he also got many ESP8266 based bunny boards, which he distributed among the participants. You can read more about one such project in Anwesha’s blog. And the rest of the details from sprints:

  • Making things blink
  • Watching Star Wars
  • Flashing Boards, then unflashing boards
  • Bunny herding
  • Thumb bitting at thee
  • Xen of V & A and the river W
  • MicroPython and the search for the Temperature Sensors 2 - the sensors are lost!
  • Asking random Chinese LED manufacturer's if they can make the impossible (turns out they are bums and can't)
  • Plotting adc values from esp8266 using matplotlib
  • Causing Bunny infestation

Full photoset

All the photos from the conference are available in my flickr album.

What about PyCon Pune 2018?

You will have to wait for few more days for the exciting announcements :) Sayan already made a call for design volunteers.

Python 101 session this Sunday

This Sunday I took a Python 101 session in the reserved-bit, the local hackerspace in Pune. I was hoping that jetlag (from the PyCon trip) would be over, but it was not the case :( But, starting at 11 AM helped.

There were around 10 participants, and all of them wrote code before in various languages. A few had previous experiences with Python. Because of different Operating Systems, and also not being able to install things on a corporate laptop, my idea of using Microsoft Azure notebook service in this session helped. This also made sure that all of us were using the same version of Python (3.6) and the same environment.

Because of the nature of the participants, I decided to skip various basic examples, and tried to more longer code just after the lunch break. During our reading a file example we figured out that the notebooks are running in Ubuntu 16.04.2 LTS (Xenial Xerus) from the /etc/os-release file.

As a whole this was fun, debugging was easy on the notebooks. At the end when people asked what IDE to try, my default answer PyCharm came up :) Btw, in the image below, on the left-hand side, you can see a function call we wrote in the session to get the latest cricket match score using requests module :)

My lightning talk in Django Girls PyCon

In the weekend before PyCon US, we had a Django Girls PyCon workshop in Portland on 12th-13th May. On 12th there were a few lightning talks, and installation before the actual workshop started on 13th.

I gave a lightning talk about PyCon US, mostly focusing the volunteer nature of the conference, and why attending the sprints is a good idea. Anwesha and /me stayed back for few more talks and later moved out to have dinner with a friend. Later, during the conference, and sprints I met many from the workshop. I want to thank Terian, and other organizers for doing the amazing work behind the workshop.

Conference travel for speakers

In Free and Open Source Software culture, conferences became an important part of the community. Most of the projects or communities do the work over this beautiful thing known as the Internet, people are taking part from the warmth of their home. Conferences are the only time when we all get a chance to meet, discuss new ideas, share the knowledge among ourselves. Conference speakers are generally the volunteers who agree to spend a lot of time to prepare and then give the talk, do the QA session. This also involves a lot of travel, for any mid-sized to a big conference, you will always find at least couple of speakers traveling half of the world to give those talks.

We, the organizers of many of these conferences can do a few things which helps the speakers to have a trouble free mind.

Inform the talk selection result as soon as possible(aka. visa takes time)

We should inform the speakers about the talk selection result as soon as possible. International traveling still requires visa for many countries, and generally, they are difficult to obtain in less time. For example, I am an Indian, and for getting a visa for most countries, I will have to submit my last three years income tax documents, last 6 months bank statements, office leave letters, and many other documents. Obtaining the documents take time, and we should make sure that the speakers have plenty of time to get this done.

Help with the travel timings

The organizers are local to the conference host city, it is better you provide some insight about travel timings to your conference speakers. They may not want to take a redeye flight, or maybe taking that early morning will provide a much better experience by skipping all the city traffic.

Be in touch during local travel

For all the conferences we organized in Pune (FUDCon 2011, 2015, PyCon Pune 2017), many of the international speakers landed in Mumbai, and then we organized cabs to pick them up, mostly all of these are between 12-4AM. They had to travel next 4 hours in the cab, we made sure to club at least 2 of the speakers in each cab, and also making sure that the drivers can speak English. Remember the language problem, as not every country speaks English fluently, and that goes same to all speakers too. If the speakers are coming on their own from the airport, make sure that they have all the details, and please try to have someone waiting for them at the airport. It is better that you introduce your volunteer to the speakers before the conference. That way when the speakers come out of the airport, they will see a familiar face waiting for them.

One of our tactics was to operate the whole speakers travel from the same hotel speakers were staying. I was awake for the 2 nights and started talking to the speakers as soon as they entered their cabs. We also talked to them during their trip to make sure that everything is okay, and they don’t uncomfortable. Only sad part was that due to lack of light many missed the beautiful view of Mumbai-Pune expressway.

During the conference days, before or after, we make sure that we have enough local volunteers to provide any help as required to the speakers. Many times it happens that the speakers prefer to visit some of the tourist locations before or after the conferences. As hosts, it goes also to our list of responsibilities, helping with the cab booking or providing suggestions for the sightseeing.

I remember the long list of speakers, and the checkbox(s) beside their names to mark that the speaker has boarded safely in the flight for their return journey. Our job is not done till the time they reach back to their home, and we make sure to keep an eye for any emergency. Many of the ideas also go to the speakers who are coming for the first time to the city from other parts of the country. In a country like India, where we have 24 official languages, it is difficult for most of Indians to understand or speak the local language in any state other than their own.

Previously, we had experiences where someone felt sick during the conference, and we have to take them to visit doctors, and making sure to check that they are okay. Telling that we have a large conference, and we can not take care of all of the people is easy, but remember the amount of effort these speakers are putting to make your conference as their own, and providing a great experience to the conference attendees.

Event report: FOSSASIA 2017

FOSSASIA 2017 reminded me of foss.in. After a long time, finally, a conference which has the similar aspects. Similar kind of tight organizing team, the presence of upstream communities from different locations. The participation from the local Singapore tech community along with Hackerspace Singapore is a serious boost. This was my 4th FOSSASIA conference, and also 3rd time in Singapore. I should thank Mario, Hong, and rest of the organizers to make this event a very pleasant experience.

This time Sayan booked an Airbnb for Anwesha and me. Saptak + Medo + Siddhesh + Praveen Patil, and Pooja Yadav, & Pravin Kumar were also staying in the same Airbnb in the Chinatown. The conference venue was the Singapore Science Center just like last year. Having the conference in the same place helps as the MRT route is very easy to reach there on time.

The day before the conference we had a speakers meetup in the Singapore Microsoft office. We also received a tour of the office, the person in-charge also explained about how are managing an office without permanent seating positions.

Day one

The conference started at 9:24AM (as Hong asked us to remember the time). I attended the talks from Harish Pillay and Chan Cheow Hoe. The idea of having the CIO of the country coming to the conference and giving a talk on Open Source is a great feeling. In 2015 we had Minister for Foreign Affairs, Mr. Vivian Balakrishnan giving a keynote (and talking about the NodeJS code he wrote). The way govt. is taking part in the local community events is something other countries should try to learn. Of course, Singapore has the benefit of being small in size.

Though the day was full of talks related to AI and machine learning, there were two talks I was waiting to attend. After lunch, the first one was from Bunnie Huang, where he spoke about making technology more inclusive. He talked about Chibitronics. Before I traveled to Singapore, I actually asked him to get a copy of his new book, The Hardware Hacker. I got my copy signed by him after his talk :) (I already finished the book while coming back to India, more on that later in a separate blog post). I also met Xobs and found a Chibtronics Love-to-Code board in his pocket :)

Later in the day, Frank Karlitschek gave his keynote titled Protecting privacy with free software. He brought up the original idea of the Internet being decentralized. The last talk of the day was a panel discussion on Artificial Intelligence.

Day 2 & Day 3

I spent most of the time in the Python track, and in between jumping around different floors of the venue meeting people. I personally had a two-hour workshop on MicroPython and NodeMCU. Anwesha was busy in the PyLadies table along with Pooja. I forgot to show the poster of PyCon APAC in the Python track :( But you can still submit talks and attend the conference. Sadly this will clash with another conference for me.

Anwesha had her talk on day 3, and her laptop's display decided to crash just before the talk. But finally the slides came back :) I also attended the SELinux workshop from Jason Zaman. He and few BSD friends convinced me to try out ZFS, and then build a new home storage with FreeNAS.

Now I have to wait for the next edition of FOSSASIA. It is a great place where I can meet my friends from different parts of the world, and share ideas :)

Building IoT enabled power-strip with MicroPython and NodeMCU

This was on my TODO list for a long time. But, never managed to time to start working on it, I was also kind of scared of doing the AC wiring without adult supervision :).

Items used

  • Power-strip
  • USB power plug (any standard mobile phone charger)
  • wires
  • NodeMCU Amica
  • Relay board
  • MicroPython
  • Mosquitto server on my home network

I ordered double relay boards (this one was marked for Arduino) from Amazon, and they were laying in the boxes in the Pune Hackerspace for a long time.

Yesterday, we had a Raspberry Pi workshop in the hackerspace as part of the Python Pune monthly meetup. Nikhil was present in the meetup, and I asked for help from him as he is a real hardware expert.

We took one of the existing power-strip from the hackerspace, and also a mobile phone charger. After taking out 2 of the power sockets we had enough space to plug-in the rest of the system inside of it. Of course, Nikhil did all the hard work of soldering the wires in the proper manner.

The relay board is connected to a NodeMCU Amica running MicroPython. It has a code like the following example:

import time
from machine import Pin
from umqtt.simple import MQTTClient

# Received messages from subscriptions will be delivered to this callback
def sub_cb(topic, msg):
    led1 = Pin(14,Pin.OUT)
    if msg == b"on_msg":
        led1.low()
    elif msg == b"off_msg":
        led1.high()

def main(server="SERVER_IP"):
    c = MQTTClient("umqtt_client", server)
    c.set_callback(sub_cb)
    c.connect()
    c.subscribe(b"your_topic")
    while True:
        c.wait_msg()
    c.disconnect()

if __name__ == "__main__":
    try:
        time.sleep(10)
        main()
    except:
        pass

I will have to cover up the holes with something, and also push the code to a proper repository. Meanwhile this was the first usable thing I made with help from friends in the Hackerspace Pune. Come and join us to have more fun and build new things.

Btw, remember to have a password protected mosquitto server :)

Running MicroPython on 96Boards Carbon

I received my Carbon from Seedstudio a few months back. But, I never found time to sit down and work on it. During FOSSASIA, in my MicroPython workshop, Siddhesh was working to put MicroPython using Zephyr on his Carbon. That gave me the motivation to have a look at the same after coming back home.

What is Carbon?

Carbon is a 96Boards IoT edition compatible board, with a Cortex-M4 chip, and 512KB flash. It currently runs Zephyr, which is a Linux Foundation hosted project to build a scalable real-time operating system (RTOS).

Setup MicroPython on Carbon

To install the dependencies in Fedora:

$ sudo dnf group install "Development Tools"
$ sudo dnf install git make gcc glibc-static \
      libstdc++-static python3-ply ncurses-devel \
      python-yaml python2 dfu-util

The next step is to setup the Zephyr SDK. You can download the latest binary from here. Then you can install it under your home directory (you don’t have to install it system-wide). I installed it under ~/opt/zephyr-sdk-0.9 location.

Next, I had to check out the zephyr source, I cloned from https://git.linaro.org/lite/zephyr.git repo. I also cloned MicroPython from the official GitHub repo. I will just copy paste the next steps below.

$ source zephyr-env.sh
$ cd ~/code/git/
$ git clone https://github.com/micropython/micropython.git
$ cd micropython/zephyr

Then I created a project file for the carbon board specially, this file is named as prj_96b_carbon.conf, and I am pasting the content below. I have submitted the same as a patch to the upstream Micropython project. It disables networking (otherwise you will get stuck while trying to get the REPL).

# No networking for carbon
CONFIG_NETWORKING=n
CONFIG_NET_IPV4=n
CONFIG_NET_IPV6=

Next, we have to build MicroPython as a Zephyr application.

$ make BOARD=96b_carbon
$ ls outdir/96b_carbon/
arch     ext          isr_tables.c  lib          Makefile         scripts  tests       zephyr.hex  zephyr.map           zephyr.strip
boards   include      isr_tables.o  libzephyr.a  Makefile.export  src      zephyr.bin  zephyr.lnk  zephyr_prebuilt.elf
drivers  isrList.bin  kernel        linker.cmd   misc             subsys   zephyr.elf  zephyr.lst  zephyr.stat

After the build is finished, you will be able to see a zephyr.bin file in the output directory.

Uploading the fresh build to the carbon

Before anything else, I connected my Carbon board to the laptop using an USB cable to the OTG port (remember to check the port name). Then, I had to press the *BOOT0 button and while pressing that one, I also pressed the Reset button. Then, left the reset button first, and then the boot0 button. If you run the dfu-util command after this, you should be able to see some output like below.

$ sudo dfu-util -l
dfu-util 0.9
Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
Found DFU: [0483:df11] ver=2200, devnum=14, cfg=1, intf=0, path="2-2", alt=3, name="@Device Feature/0xFFFF0000/01*004 e", serial="385B38683234"
Found DFU: [0483:df11] ver=2200, devnum=14, cfg=1, intf=0, path="2-2", alt=2, name="@OTP Memory /0x1FFF7800/01*512 e,01*016 e", serial="385B38683234"
Found DFU: [0483:df11] ver=2200, devnum=14, cfg=1, intf=0, path="2-2", alt=1, name="@Option Bytes /0x1FFFC000/01*016 e", serial="385B38683234"
Found DFU: [0483:df11] ver=2200, devnum=14, cfg=1, intf=0, path="2-2", alt=0, name="@Internal Flash /0x08000000/04*016Kg,01*064Kg,03*128Kg", serial="385B38683234"

This means the board is in DFU mode. Next we flash the new application to the board.

$ sudo dfu-util -d [0483:df11] -a 0 -D outdir/96b_carbon/zephyr.bin -s 0x08000000
dfu-util 0.9
Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2016 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/
dfu-util: Invalid DFU suffix signature
dfu-util: A valid DFU suffix will be required in a future dfu-util release!!!
Opening DFU capable USB device...
ID 0483:df11
Run-time device DFU version 011a
Claiming USB DFU Interface...
Setting Alternate Setting #0 ...
Determining device status: state = dfuERROR, status = 10
dfuERROR, clearing status
Determining device status: state = dfuIDLE, status = 0
dfuIDLE, continuing
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash "
Downloading to address = 0x08000000, size = 125712
Download [=========================] 100% 125712 bytes
Download done.
File downloaded successfully

Hello World on Carbon

The hello world of the hardware land is the LED blinking code. I used the on-board LED(s) for the same, the sample code is given below. I have now connected the board to the UART (instead of OTG).

$ screen /dev/ttyUSB0 115200
>>>
>>> import time
>>> from machine import Pin
>>> led1 = Pin(("GPIOD",2), Pin.OUT)
>>> led2 = Pin(("GPIOB",5), Pin.OUT)
>>> while True:
... led2.low()
... led1.high()
... time.sleep(0.5)
... led2.high()
... led1.low()
... time.sleep(0.5)

Having emojis in your Ubiquiti SSID

Ubiquiti management interface does not allow to have emojis in the network SSID. After asking over twitter about it, Donald Stufft pointed me to a hack in their forum.

First, create a second wifi network, and then you will have to copy the /tmp/system.cfg file from the access point.

scp yourusername@192.168.1.IP:/tmp/system.cfg .

After this open up the system.cfg in your favorite editor, replace the newly created network name with the emoji text you want. Copy it back to the access point. After this ssh into the access point, it will give you a busybox prompt. Type save command in the prompt, and then reboot the access point from the web-console. This will give you the SSID you were looking for :)

Testing Fedora MariaDB layered image using gotun

Testing Fedora MariaDB layered image testing using gotun

Yesterday Adam Miller announced the availability of the latest Fedora Layered Image release. The following container images are available in the Fedora registry:

  • registry.fedoraproject.org/f25/cockpit:130-1.3.f25docker
  • registry.fedoraproject.org/f25/cockpit:130
  • registry.fedoraproject.org/f25/cockpit
  • registry.fedoraproject.org/f25/kubernetes-node:0.1-3.f25docker
  • registry.fedoraproject.org/f25/kubernetes-node:0.1
  • registry.fedoraproject.org/f25/kubernetes-node
  • registry.fedoraproject.org/f25/mariadb:10.1-2.f25docker
  • registry.fedoraproject.org/f25/mariadb:10.1
  • registry.fedoraproject.org/f25/mariadb
  • registry.fedoraproject.org/f25/kubernetes-apiserver:0.1-3.f25docker
  • registry.fedoraproject.org/f25/kubernetes-apiserver:0.1
  • registry.fedoraproject.org/f25/kubernetes-apiserver
  • registry.fedoraproject.org/f25/kubernetes-master:0.1-5.f25docker
  • registry.fedoraproject.org/f25/kubernetes-master:0.1
  • registry.fedoraproject.org/f25/kubernetes-master
  • registry.fedoraproject.org/f25/flannel:0.1-3.f25docker
  • registry.fedoraproject.org/f25/flannel:0.1
  • registry.fedoraproject.org/f25/flannel
  • registry.fedoraproject.org/f25/kubernetes-proxy:0.1-3.f25docker
  • registry.fedoraproject.org/f25/kubernetes-proxy:0.1
  • registry.fedoraproject.org/f25/kubernetes-proxy
  • registry.fedoraproject.org/f25/etcd:0.1-5.f25docker
  • registry.fedoraproject.org/f25/etcd:0.1
  • registry.fedoraproject.org/f25/etcd
  • registry.fedoraproject.org/f25/toolchain:1-2.f25docker
  • registry.fedoraproject.org/f25/toolchain:1
  • registry.fedoraproject.org/f25/toolchain

Now, I am going to show how we can add a set of tests for the MariaDB container under gotun on a Fedora Atomic host. I will be firing up the job in the Fedora Infra Cloud.

Because of the nature of the Atomic host, I decided to write a set of tests in golang and build a static binary which can be executed inside of the Atomic host. This way we do not have to worry about any dependency in the host.

$ ldd tunirtests.test
	not a dynamic executable

Source code of the test

The following is the source for mysql_test.go.

package main

import (
	"testing"
	"database/sql"
	 _ "github.com/go-sql-driver/mysql"
)

func TestMariadb(t *testing.T) {
	db, err := sql.Open("mysql", "user:password@/dbname")
	if err != nil {
		t.Fatal("Can not connect to mariadb", err.Error())
	}
	defer db.Close()
	stmt := "CREATE TABLE IF NOT EXISTS funny (id int(5) NOT NULL AUTO_INCREMENT, name varchar(250), PRIMARY KEY(id))"
	_, err = db.Exec(stmt)
	if err != nil {
		t.Fatal("Can not create table", err.Error())
	}

	_, err = db.Exec("INSERT INTO funny VALUES (?,?)",1,"kushal")
	if err != nil {
		t.Fatal("Can not insert data", err.Error())
	}
	_, err = db.Exec("INSERT INTO funny VALUES (?,?)",2,"Python")
	if err != nil {
		t.Fatal("Can not insert data", err.Error())
	}
	rows, err := db.Query("SELECT * from funny")
	for rows.Next() {
		var uid int
		var name string
		err := rows.Scan(&uid, &name)
		if err != nil {
			t.Fatal("Error in selecting data", err.Error())
		}
		if uid == 1 {
			if name != "kushal" {
				t.Fatal("Oops, data mismatch", name)
			}
		}
	}

}

As you can see above that I have hardcoded username, password and dub name in the source. This is because while starting the Mariadb container, I can pass those values to the container using environment variables.

I am creating a table, inserting 2 rows in it. Then selecting those rows back to the tool.

the gotun job test file

The following is the content of the mariadb.txt file.

curl -O https://kushal.fedorapeople.org/tunirtests.test
sudo docker run -d --name mariadb_database -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=dbname -p 3306:3306 registry.fedoraproject.org/f25/mariadb
SLEEP 30
chmod +x tunirtests.test
./tunirtests.test -test.run TestMariadb -test.v

At first, I am downloading the binary test file from my Fedora people space. We can also push it to the VM from the host using COPY directive. Next, I am running the docker command to fire up the container with all the required environment variables. After that, I am sleeping for 30 seconds as it takes time to get that container ready for usage. In the last line, I am executing the binary to test the container. Now, we can add more fancy command line arguments to the docker run command (like a data volume), and then test those too. But, I am going to keep those as an exercise for the reader :)

If you have any comment, feel free to drop me a mail, or tweet to @kushaldas.

The final output from the test is also given below.

./gotun --job mariadb
Starts a new Tunir Job.

Server ID: 9c4168ae-d8c4-4534-a53c-c2a291d4f6c5
Let us wait for the server to be in running state.
Time to assign a floating pointip.
Polling for a successful ssh connection.

Polling for a successful ssh connection.

Polling for a successful ssh connection.

Polling for a successful ssh connection.

Polling for a successful ssh connection.

Executing:  curl -O https://kushal.fedorapeople.org/tunirtests.test
Executing:  sudo docker run -d --name mariadb_database -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=dbname -p 3306:3306 registry.fedoraproject.org/f25/mariadb
Sleeping for  30
Executing:  chmod +x tunirtests.test
Executing:  ./tunirtests.test -test.run TestMariadb -test.v
---------------


Result file at: /tmp/tunirresult_586858839


Job status: true


command: curl -O https://kushal.fedorapeople.org/tunirtests.test
status:true

  %!T(MISSING)otal    %!R(MISSING)eceived %!X(MISSING)ferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 4347k  100 4347k    0     0  3722k      0  0:00:01  0:00:01 --:--:-- 3725k


command: sudo docker run -d --name mariadb_database -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=dbname -p 3306:3306 registry.fedoraproject.org/f25/mariadb
status:true

Unable to find image 'registry.fedoraproject.org/f25/mariadb:latest' locally
Trying to pull repository registry.fedoraproject.org/f25/mariadb ... 
sha256:9a2c3bc162b6b1a1c286302c3e635d77c6e31cbca5d354ed0a839c659e1ecfdc: Pulling from registry.fedoraproject.org/f25/mariadb
be44cf43edd1: Pull complete 
a87762b3425a: Pull complete 
Digest: sha256:9a2c3bc162b6b1a1c286302c3e635d77c6e31cbca5d354ed0a839c659e1ecfdc
Status: Downloaded newer image for registry.fedoraproject.org/f25/mariadb:latest
e9c72f1f41b1ec763418f969359c3319bdc4c95d8123fc3b5e6617768b90d00f


command: chmod +x tunirtests.test
status:true



command: ./tunirtests.test -test.run TestMariadb -test.v
status:true

=== RUN   TestMariadbConnect
--- PASS: TestMariadbConnect (0.20s)
PASS


Total Number of Tests:4
Total NonGating Tests:0
Total Failed Non Gating Tests:0

Success.