Archive for the 'Uncategorized' Category

Setting KVM hostname per DHCP

The Problem

One problem with virtual machines is, when you clone one you also copy the complete configuration including hostname, static IPs, etc. To fix this you need to boot the cloned VM, edit the config and reboot it. The problem is that you will have at least temporary hostname and/or IP conflicts.

Use DHCP

The better approach is to obtain hostnames and IPs via DHCP.
Then when you clone a machine (e.g. using virt-manager) for testing software updates or other changes, you simply remove the external NIC from the cloned VM, and the internal NIC gets a new MAC assigned automatically.
Then you update the DHCP server configuration (e.g. /etc/dnsmasq.conf) and add the new MAC, assigned IP and hostname there. Then when booting the new VM it automatically gets the correct hostname and new IP, without the need of changing the VM’s configuration files.

Example:

dhcp-host=52:54:00:B9:C5:06,redmine,192.168.0.14,30m
dhcp-host=52:54:00:BF:70:1C,redmine-test,192.168.0.19,30m

After the changes have been tested successfully you can apply the changes to the real system (you still should have a backup).
Don’t remove the cloned ‘test-vm’. Just shut it down and keep it for the next time.

When you need to test again some new changes on the machine you have already the complete clone configuration and MAC address DHCP setup. So you simply need to replace the clone’s disk file (e.g. redmine-clone.qcow) with the latest version of your VM’s disk file (e.g. redmine.qcow). Then you can start the test machine and everything should work just fine without any conflicts.

Example SSH Session:

# log into the VM's host system
ssh -l root blade7
cd /var/lib/libvirt/images
# shutdown the VM before copying the file
virsh shutdown Redmine
cp redmine.qcow redmine-test.qcow
# Restart VM
virsh start Redmine
# Start Clone-VM
virsh start Redmine-test
exit

Configuring the DHCP-Client on Debian (VM Guest)

On Debian you simply need to set the hostname in /etc/hostname to “localhost” to enable receiving the hostname via DHCP.
The DHCP client itself is already configured to request “host-name” info via DHCP. See /etc/dhcp/dhclient.conf. There you should find the option “host-name” in the list of requested DHCP options.

About DNSmasq

As a side note I should mention that using DNSmasq is a great solution. It is a DHCP server and DNS server in one application.
This means no matter if you are adding hostnames manually to the DHCP configuration or getting hostnames via DHCP from any DHCP client, these names can be also resolved via DNS automatically, without any further configuration.

Advertisements

VS2017 has got CMake support

We are using CMake already for years in my company to develop cross-platform software. CMake is really a great piece of software, but the user experience in Visual Studio was not great. It worked, but we often needed to explain how, and the typical Visual Studio user didn’t know CMake at all.

Now CMake support has been built into Visual Studio directly, which means

  • you can open CMake projects directly.
  • there is no need to generate Visual Studio solutions anymore.
  • you can configure CMake options from the GUI.
  • you can directly execute CMake targets like “install” from the Solution Explorer.

Watch this video to see it in action:
https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/

This is is really some great news for the Visual Studio world.
Hopefully even more developers will use CMake now in the future.

Fix performance of VIM syntax highlighting in XML files

Normally Vim is damn fast and this is one reason why I love it. But today I got an XML file with over 3 million lines and after opening that file I wanted to jump to the end of the file. This took me over 1 minute which is unacceptable. Turning of syntax highlighting fixes this performance issue, but of course I don’t want to disable it.

I found the solution on stack overflow:
http://stackoverflow.com/questions/19030290/syntax-highlighting-causes-terrible-lag-in-vim

The problem was caused by one regex entry of syntax/xml.vim.
The line containing the regex for xmlSyncDT was causing this issue.

" synchronizing
" TODO !!! to be improved !!!

syn sync match xmlSyncDT grouphere  xmlDocType +\_.\(<!DOCTYPE\)\@=+

By commenting this out the performance issue is gone without noticeable sideeffects. The comment above the line shows already that the developer of this file is not happy with it. I can live perfectly without this.
Now I can jump to the end of the 3 million line file without any noticeable delays.

The post on Stackoverflow shows also how to debug such issues:

:syntime on
// do something
:syntime report

This statistic shows you where in the syntax highlighter the CPU time gets “burned”.

Easily debug unit tests with GDB

A while ago I developed an ANSI C based unittest framework that gives me the same comfort as the Qt’s unit test framework in C++, but small and portable for embedded ANSI C applications.

You can find the framework here on github :http://gergap.github.io/unittest

This framework also supports data-driven tests, which means you write one test case and can execute the same test n times with different data sets. When something goes wrong you need to debug this. Therefor you can pass the name of the testcase as commandline argument, which means only this testcase gets executed. If it’s a data-driven test this still gets called n times, so there is a second command line argument which contains the dataset name. Now the testcase gets executed only one time with the data set causing the problem.

This is already quiet cool and worked good. But I’m lazy. I didn’t want to open the correct file in the debugger, set the breakpoint, start the application with the correct arguments and let it run to the problematic line. So now I automated also this.

Now you can simply invoke the test with the option “-g” (like debugging in GCC), nothing more. Then the test will abort on the first error and creates a file called ‘test.gdb’ with all instructions necessary to debug this problem.
Then you start GDB with this file and you are there where you want.

Here is an example of the unittest output:

Unit test output

When you run the cgdb as shown in the output you jump right into the debugger with one breakpoint set at the start of the test case and one breakpoint at the error location. You can decide if you want to step to the error or if you simply hit ‘c’ (continue) to run to the error location. Sometimes it also helps to start history recording before pressing continue, so you can use reverse-stepping if you have missed an important line.

Unit test debugging

The generated test.gdb file which does the magic for you only contains three lines:

break test_strtouint16
break ../src/test/utiltest/strtoint.c:277
run test_strtouint16 padding

This new feature is not yet on github, but I’ll upload it soon.
I think it’s a really useful and simple feature.

It would be cool to see this in other unit test frameworks too in the future.

Windows10 sucks

Yesterday I needed Windows to build a product release for the Windows platform.
Normally I don’t do this, but the colleague was on vacation. I normally touch Windows only a few times a year, and I don’t waste my time and hard disk on installing Windows. Even though I grew up with DOS and Windows I stopped using it, because it makes way too much troubles and Linux works rock solid.

So I booted the colleague’s PC and guess what? It automatically installed some updates without asking. After this the network didn’t work anymore. So I could not execute the build process, which is in a VirtualBox VM anyway. Unfortunately the copy of the VM image on our network share was out of date, so I wanted to copy the image from the PC to the network share – oops, no network. So I tried to copy it to an external hard disk connected via USB. Guess what, Windows10 was not able to recognize this disk. On another WindowsXP machine the disk worked, but not on Windows10 – Happy Anniversary update !!!

Why is this Windows shit always hitting me? I touch Windows as rarely as I can, but always there is a problem. Bluescreeens, “utltra-fast” reboots, something hangs or does not work at all.

On every new Windows version people tell me: “Now it’s much better, no blue screens anymore, bla bla”. And every time I try Windows it is the same crap as before or even worse…

Sorry, normally my post are more objective, but this Windows crap pisses me off. I again lost two work days with fixing this crap. Why to hell I didn’t simply boot a Linux SystemRescue CD and copied over the VM to my Linux box? Good question – I think because I was expecting a simple solution. The next time I will not waste my time with Windows anymore – simply use Linux and stay relaxed.

Wombat256 for #Vim has now an own Git Repo

I just moved my wombat256 colorscheme for console #Vim to a separate Git repository.
This makes it easier for you guys to use it simply by using pathogen & Co.
I also updated my Vim repo to make use of this separate repo.

Checkout it out on https://github.com/gergap/wombat256

Vim Section Navigation

Normally #Vim uses easy to remember mnemonics like d2w (delete two words).
But when it comes to section navigation using ‘[[‘, ‘]]’, ‘[]’, and ‘][‘ it looks weired.
At least if you expect, that the opening and closing brackets are somehow matching opening
and closing braces.

(In C like languages function scopes {…} are sections so you can easily jump
to the next or previous function.)

I tried to figure out the system behind so that this is easy to remember for me.
Most of the time you want to jump to the start of function, so to a ‘{‘.
Vim tries to make typing easy, and because pressing a key twice is easier than pressing two different keys,
Vim uses ‘[[‘ to jump to the previous ‘{‘ and ‘]]’ for jumping to the next ‘{‘.
The first bracket gives the direction. By repeating the key you say “jump to an opening brace”.

For the case that you want to jump to a closing ‘}’ just use the other key. The first direction key stays the same.
So ‘[]’ jumps to the previous ‘}’ and ‘][‘ goes to the next ‘}’.

Summary:

  • The direction is obvious and easy to remember
  • Jump to a opening brace: repeat key
  • Jump to a closing brace: use the other key

If you are new to Vim, please check out also ‘{‘, ‘}’, ‘(‘, ‘)’, ‘%’, w, b for navigation.
Every Vim user should know these keys.
Use “:help <key>” to get help for it.