Permalink
Browse files

autotools: Introduce cpplint and gofmt

Include code style checking in the "make check" command.

Fixes #28
  • Loading branch information...
Michal Rostecki
Michal Rostecki committed Sep 20, 2016
1 parent 962b7ae commit 26c26094286132edc71e1392f3b280eb897791af
@@ -71,8 +71,11 @@ Makefile.in
# Tests
*.log
*.test
!cpplint.test
!gofmt.test
!go.test
*.trs
.deps
.dirstamp
cpplint.py
test-driver
@@ -18,6 +18,9 @@ export CGO_LDFLAGS=$(LDFLAGS)

SUBDIRS = pkg/download pkg/etcdtools pkg/libvirttools pkg/manager

check_SCRIPTS = cpplint.test gofmt.test
TESTS = $(check_SCRIPTS)

.PHONY: all vendor

all:
@@ -92,8 +92,8 @@ func main() {
mountName := "TestImg.img"
hostPath := "/var/lib/virtlet"
config := &kubeapi.ContainerConfig{
Image: imageSpec,
Mounts: []*kubeapi.Mount{&kubeapi.Mount{Name:&mountName, HostPath: &hostPath}},
Image: imageSpec,
Mounts: []*kubeapi.Mount{&kubeapi.Mount{Name: &mountName, HostPath: &hostPath}},
}
containerIn := &kubeapi.CreateContainerRequest{
PodSandboxId: sandboxOut.PodSandboxId,
@@ -0,0 +1,7 @@
#!/bin/sh

if [ ! -f cpplint.py ]; then
curl -O https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py
fi
chmod +x cpplint.py
./cpplint.py --extensions=c,h --filter=-build/include,-whitespace/tab $(find . -regextype posix-egrep -regex ".*\.(c|h)$")
@@ -0,0 +1,3 @@
#!/bin/sh

go fmt $(go list ./... | grep -v /vendor/ | grep -v guestfs)
@@ -24,10 +24,8 @@ limitations under the License.
#include <unistd.h>
#include "image.h"

int
virtletVolUploadSource(virStreamPtr stream, char *bytes, size_t nbytes,
void *opaque)
{
int virtletVolUploadSource(virStreamPtr stream, char *bytes, size_t nbytes,
void *opaque) {
if (opaque == NULL) {
return -1;
}
@@ -36,10 +34,8 @@ virtletVolUploadSource(virStreamPtr stream, char *bytes, size_t nbytes,
return read(*fd, bytes, nbytes);
}

int
pullImage(virConnectPtr conn, virStoragePoolPtr pool, char *shortName, char *filepath,
char *volXML)
{
int pullImage(virConnectPtr conn, virStoragePoolPtr pool, char *shortName,
char *filepath, char *volXML) {
int result = 0;
virStorageVolPtr vol = NULL;
int fd = -1;
@@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef VIRTLET_IMAGE_H
#define VIRTLET_IMAGE_H
#ifndef PKG_LIBVIRTTOOLS_IMAGE_H_
#define PKG_LIBVIRTTOOLS_IMAGE_H_

#include <stdbool.h>

int virtletVolUploadSource(virStreamPtr stream, char *bytes, size_t nbytes,
void *opaque);
int pullImage(virConnectPtr conn, virStoragePoolPtr pool, char *shortName, char *filepath,
char *volXML);
void *opaque);
int pullImage(virConnectPtr conn, virStoragePoolPtr pool, char *shortName,
char *filepath, char *volXML);

#endif /* VIRTLET_IMAGE_H */
#endif // PKG_LIBVIRTTOOLS_IMAGE_H_
@@ -24,9 +24,9 @@ package libvirttools
import "C"

import (
"fmt"
"github.com/golang/glog"
"unsafe"
"fmt"
)

const (
@@ -36,14 +36,14 @@ const (

type Pool struct {
volumesPoolDir string
poolType string
poolType string
}

type PoolSet map[string]*Pool

var DefaultPools PoolSet = PoolSet{
"default": &Pool {volumesPoolDir: "/var/lib/libvirt/images", poolType: poolTypeDir},
"volumes": &Pool {volumesPoolDir: "/var/lib/virtlet", poolType: poolTypeDir},
"default": &Pool{volumesPoolDir: "/var/lib/libvirt/images", poolType: poolTypeDir},
"volumes": &Pool{volumesPoolDir: "/var/lib/virtlet", poolType: poolTypeDir},
}

func generatePoolXML(name string, path string, poolType string) string {
@@ -15,6 +15,7 @@ limitations under the License.
*/

package libvirttools

/*
#include <libvirt/libvirt.h>
#include <libvirt/virterror.h>
@@ -24,18 +25,18 @@ import "C"

import (
"fmt"
"unsafe"
"github.com/golang/glog"
"unsafe"
)

const (
defaultCapacity = 1024
defaultCapacity = 1024
defaultCapacityUnit = "MB"
)

type StorageBackend interface {
GenerateVolXML(pool C.virStoragePoolPtr, shortName string, capacity int, capacityUnit, libvirtFilepath string) string
CreateVol (pool C.virStoragePoolPtr, volName string, capacity int, capacityUnit string) (C.virStorageVolPtr, error)
CreateVol(pool C.virStoragePoolPtr, volName string, capacity int, capacityUnit string) (C.virStorageVolPtr, error)
}

func GetStorageBackend(name string) (StorageBackend, error) {
@@ -50,7 +51,7 @@ func GetStorageBackend(name string) (StorageBackend, error) {

type LocalFilesystemBackend struct{}

func (LocalFilesystemBackend) GenerateVolXML(pool C.virStoragePoolPtr,shortName string, capacity int, capacityUnit string, path string) string {
func (LocalFilesystemBackend) GenerateVolXML(pool C.virStoragePoolPtr, shortName string, capacity int, capacityUnit string, path string) string {
volXML := `
<volume>
<name>%s</name>
@@ -69,7 +70,7 @@ func (RBDBackend) GenerateVolXML(pool C.virStoragePoolPtr, shortName string, cap
return ""
}

func (LocalFilesystemBackend) CreateVol (pool C.virStoragePoolPtr, volName string, capacity int, capacityUnit string) (C.virStorageVolPtr, error) {
func (LocalFilesystemBackend) CreateVol(pool C.virStoragePoolPtr, volName string, capacity int, capacityUnit string) (C.virStorageVolPtr, error) {
volXML := `
<volume>
<name>%s</name>
@@ -87,7 +88,7 @@ func (LocalFilesystemBackend) CreateVol (pool C.virStoragePoolPtr, volName strin
return vol, nil
}

func (RBDBackend) CreateVol (pool C.virStoragePoolPtr, volName string, capacity int, capacityUnit string) (C.virStorageVolPtr, error) {
func (RBDBackend) CreateVol(pool C.virStoragePoolPtr, volName string, capacity int, capacityUnit string) (C.virStorageVolPtr, error) {
return nil, nil
}

@@ -118,7 +119,6 @@ func LookupVol(name string, pool C.virStoragePoolPtr) (C.virStorageVolPtr, error
return vol, nil
}


func RemoveVol(name string, pool C.virStoragePoolPtr) error {
vol, err := LookupVol(name, pool)
if err != nil {
@@ -19,8 +19,7 @@ limitations under the License.
#include <libvirt/libvirt.h>
#include "image.h"

void testVirtletVolUploadSourceNullOpaque()
{
void testVirtletVolUploadSourceNullOpaque() {
virConnectPtr conn;
virStreamPtr stream;
int result;
@@ -43,11 +42,10 @@ void testVirtletVolUploadSourceNullOpaque()
}
}

int
main(int argc, char **argv)
{
int main(int argc, char **argv) {
g_test_init(&argc, &argv, NULL);
g_test_add_func("/virtletVolUploadSourceNullOpaque", &testVirtletVolUploadSourceNullOpaque);
g_test_add_func("/virtletVolUploadSourceNullOpaque",
&testVirtletVolUploadSourceNullOpaque);

return g_test_run();
}
@@ -19,9 +19,7 @@ limitations under the License.
#include <stdlib.h>
#include "virtualization.h"

int
defineDomain(virConnectPtr conn, char *domXML)
{
int defineDomain(virConnectPtr conn, char *domXML) {
int result = 0;
virDomainPtr domain = NULL;

@@ -36,9 +34,7 @@ defineDomain(virConnectPtr conn, char *domXML)
return result;
}

int
createDomain(virConnectPtr conn, char *uuid)
{
int createDomain(virConnectPtr conn, char *uuid) {
int result = 0;
virDomainPtr domain = NULL;

@@ -54,9 +50,7 @@ createDomain(virConnectPtr conn, char *uuid)
return result;
}

int
stopDomain(virConnectPtr conn, char *uuid)
{
int stopDomain(virConnectPtr conn, char *uuid) {
int result = 0;
virDomainPtr domain = NULL;

@@ -72,9 +66,7 @@ stopDomain(virConnectPtr conn, char *uuid)
return result;
}

int
destroyAndUndefineDomain(virConnectPtr conn, char *uuid)
{
int destroyAndUndefineDomain(virConnectPtr conn, char *uuid) {
int result = 0;
virDomainPtr domain = NULL;

@@ -31,9 +31,9 @@ import (

kubeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"

"encoding/xml"
"github.com/Mirantis/virtlet/pkg/etcdtools"
"github.com/Mirantis/virtlet/pkg/utils"
"encoding/xml"
"github.com/golang/glog"
)

@@ -57,21 +57,21 @@ type Target struct {
}

type Disk struct {
DiskType string `xml:"type,attr"`
DiskType string `xml:"type,attr"`
DiskDevice string `xml:"device,attr"`
Drive Drive `xml:"drive"`
Src Source `xml:"source"`
Target Target `xml:"target"`
Drive Drive `xml:"drive"`
Src Source `xml:"source"`
Target Target `xml:"target"`
}

type Devices struct {
DiskList []Disk `xml:"disk"`
Inpt Input `xml:"input"`
Graph Graphics `xml:"graphics"`
Serial Serial `xml:"serial"`
Consl Console `xml:"console"`
Snd Sound `xml:"sound"`
Items []Tag `xml:",any"`
DiskList []Disk `xml:"disk"`
Inpt Input `xml:"input"`
Graph Graphics `xml:"graphics"`
Serial Serial `xml:"serial"`
Consl Console `xml:"console"`
Snd Sound `xml:"sound"`
Items []Tag `xml:",any"`
}

type Tag struct {
@@ -81,14 +81,14 @@ type Tag struct {

type Domain struct {
XMLName xml.Name `xml:"domain"`
DomType string `xml:"type,attr"`
Devs Devices `xml:"devices"`
Items []Tag `xml:",any"`
DomType string `xml:"type,attr"`
Devs Devices `xml:"devices"`
Items []Tag `xml:",any"`
}

type Input struct {
Type string `xml:"type,attr"`
Bus string `xml:"bus,attr"`
Bus string `xml:"bus,attr"`
}

type Graphics struct {
@@ -97,7 +97,7 @@ type Graphics struct {
}

type Console struct {
Type string `xml:"type,attr"`
Type string `xml:"type,attr"`
Target TargetConsole `xml:"target"`
}

@@ -107,8 +107,8 @@ type TargetConsole struct {
}

type Serial struct {
Type string `xml:"type,attr"`
Target TargetSerial `xml:"target"`
Type string `xml:"type,attr"`
Target TargetSerial `xml:"target"`
}

type TargetSerial struct {
@@ -126,7 +126,7 @@ var volXML string = `
<target dev='vda' bus='virtio'/>
</disk>`

func (v *VirtualizationTool) processVolumes (mounts []*kubeapi.Mount, domXML string) (string, error) {
func (v *VirtualizationTool) processVolumes(mounts []*kubeapi.Mount, domXML string) (string, error) {
copyDomXML := domXML
if len(mounts) == 0 {
return domXML, nil
@@ -153,7 +153,7 @@ func (v *VirtualizationTool) processVolumes (mounts []*kubeapi.Mount, domXML str
return copyDomXML, err
}
volXML = fmt.Sprintf(volXML, path)
disk:= &Disk{}
disk := &Disk{}
err = xml.Unmarshal([]byte(volXML), disk)
disk.Target.TargetDev = "vdc"
if err != nil {
@@ -214,13 +214,13 @@ func generateDomXML(name string, memory int64, uuid string, vcpu int64, imageFil
}

type VirtualizationTool struct {
conn C.virConnectPtr
volumeStorage StorageBackend
volumePool C.virStoragePoolPtr
conn C.virConnectPtr
volumeStorage StorageBackend
volumePool C.virStoragePoolPtr
volumePoolName string
}

func NewVirtualizationTool(conn C.virConnectPtr, poolName string, storageBackendName string) (*VirtualizationTool, error){
func NewVirtualizationTool(conn C.virConnectPtr, poolName string, storageBackendName string) (*VirtualizationTool, error) {
pool, err := LookupStoragePool(conn, poolName)
if err != nil {
return nil, err
@@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef VIRTLET_VIRTUALIZATION_H
#define VIRTLET_VIRTUALIZATION_H
#ifndef PKG_LIBVIRTTOOLS_VIRTUALIZATION_H_
#define PKG_LIBVIRTTOOLS_VIRTUALIZATION_H_

int defineDomain(virConnectPtr conn, char *domXML);
int createDomain(virConnectPtr conn, char *uuid);
int stopDomain(virConnectPtr conn, char *uuid);
int destroyAndUndefineDomain(virConnectPtr conn, char *uuid);

#endif /* VIRTLET_VIRTUALIZATION_H */
#endif // PKG_LIBVIRTTOOLS_VIRTUALIZATION_H_
Oops, something went wrong.

0 comments on commit 26c2609

Please sign in to comment.