createtest.c revision 72d0e1cb2facaa4b8ba2f15e311d6bb9491badb7
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen * Copyright © 2012 Canonical Ltd.
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen * This program is free software; you can redistribute it and/or modify
58be9d6bcc3800f5b3d76a064ee767fbe31a5a8aTimo Sirainen * it under the terms of the GNU General Public License version 2, as
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen * published by the Free Software Foundation.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * This program is distributed in the hope that it will be useful,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * GNU General Public License for more details.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * You should have received a copy of the GNU General Public License along
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * with this program; if not, write to the Free Software Foundation, Inc.,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ad850190d946d34966a56838cfdb216e021b5b5fTimo Sirainen if ((c = lxc_container_new(MYNAME)) == NULL) {
ad850190d946d34966a56838cfdb216e021b5b5fTimo Sirainen fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainen if (!c->set_config_item(c, "lxc.network.type", "veth")) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fprintf(stderr, "%d: failed to set network type\n", __LINE__);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen c->set_config_item(c, "lxc.network.link", "lxcbr0");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen c->set_config_item(c, "lxc.network.flags", "up");
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (!c->createl(c, "ubuntu", "-r", "lucid", NULL)) {
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen fprintf(stderr, "%d: failed to create a lucid container\n", __LINE__);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fprintf(stderr, "%d: %s started, you have 60 seconds to test a console\n", __LINE__, MYNAME);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen sleep(60); // wait a minute to let user connect to console
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (!c->stop(c)) {
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen fprintf(stderr, "%d: failed to stop %s\n", __LINE__, MYNAME);
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen if (!c->destroy(c)) {
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen fprintf(stderr, "%d: error deleting %s\n", __LINE__, MYNAME);
3b20a37cb65c70f55e48dbdc912313fdacdab630Timo Sirainen fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen fprintf(stderr, "all lxc_container tests passed for %s\n", c->name);